poj 1046 Color Me Less

简介:

这道题也是一道很水的题,一个简单的数学计算,再就是找到集合中的最小的值就可以了,反正暴搜一遍就可以了,数据量也不大,不然就得sort()了。。。

但是还是学得到小技巧,就是     INT_MAX 要用到头文件<iostream>  ,我试了一下 INT_MAX 的值是 2147483647,就是   int型(有符号)最大的数。。。

另外就是读懂题意很重要了,再简单的题目,读不懂题目也白搭

这道题目的大致含义是:现输入16种颜色,然后输入N种颜色,依次输出与后面N种颜色最接近的颜色。
颜色与颜色之间的距离用D表示,两种颜色的距离


AC的代码:


#include<stdio.h>
#include<iostream>		//INT_MAX 要用到的头文件

int main()
{
	int a[17],b[17],c[17];
	int x,y,z,i,pos;
	double minDis,tmp;
	
	//输入内部数据
	for(i=0;i<16;i++)
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	
	//testcase
	while(scanf("%d%d%d",&x,&y,&z))
	{
		if(x==-1 && y==-1 && z==-1)
			break;

		minDis=INT_MAX;
		for(i=0;i<16;i++)
		{
			tmp=(x-a[i])*(x-a[i])+(y-b[i])*(y-b[i])+(z-c[i])*(z-c[i]);

			if(tmp<minDis)
			{
				minDis=tmp;
				pos=i;
			}
		}
		
		printf("(%d,%d,%d) maps to (%d,%d,%d)\n",x,y,z,a[pos],b[pos],c[pos]);
	}

	return 0;
}


相关文章
|
4月前
|
Java
hdu-1312-Red and Black
hdu-1312-Red and Black
29 0
HDU - 1312 Red and Black(DFS)
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, he can move only on black tiles. Write a program to count the number of black
77 0
hdu 1312 Red and Black(BFS)
hdu 1312 Red and Black(BFS)
136 0
hdu 1312 Red and Black
一个人从@点出发,求他所能到达的'.'的数目,'#'不可走,@本身算1个点。 思路:搜索入门题。
143 0
HDOJ 1312 (POJ 1979) Red and Black
HDOJ 1312 (POJ 1979) Red and Black
107 0
ZOJ1067 Color Me Less
复制代码#include <iostream> #include <cmath> #include <limits> using namespace std; const int MAXSIZE = 100; int pos[100];//记录对应的最小值所在位置 struct RGB {//颜.
1449 0
|
Java 机器学习/深度学习
HDU 1556 Color the ball
Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18404    Accepted Submission(s...
824 0