1046 Color Me Less

原创 2012年08月30日 11:04:43

Description

A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just such a mapping in a standard twenty-four bit RGB color space. The input consists of a target set of sixteen RGB color values, and a collection of arbitrary RGB colors to be mapped to their closest color in the target set. For our purposes, an RGB color is defined as an ordered triple (R,G,B) where each value of the triple is an integer from 0 to 255. The distance between two colors is defined as the Euclidean distance between two three-dimensional points. That is, given two colors (R1,G1,B1) and (R2,G2,B2), their distance D is given by the equation 

Input

The input is a list of RGB colors, one color per line, specified as three integers from 0 to 255 delimited by a single space. The first sixteen colors form the target set of colors to which the remaining colors will be mapped. The input is terminated by a line containing three -1 values.

Output

For each color to be mapped, output the color and its nearest color from the target set. 

If there are more than one color with the same smallest distance, please output the color given first in the color set.

Sample Input

0 0 0
255 255 255
0 0 1
1 1 1
128 0 0
0 128 0
128 128 0
0 0 128
126 168 9
35 86 34
133 41 193
128 0 128
0 128 128
128 128 128
255 0 0
0 1 0
0 0 0
255 255 255
253 254 255
77 79 134
81 218 0
-1 -1 -1

Sample Output

(0,0,0) maps to (0,0,0)
(255,255,255) maps to (255,255,255)
(253,254,255) maps to (255,255,255)
(77,79,134) maps to (128,128,128)
(81,218,0) maps to (126,168,9)


CODE:

#include <iostream>

typedef struct
{
	int r;
	int g;
	int b;
} Color;

int main(int argc, char* argv[])  
{  
	int min,i,j,temp;
	int r,g,b;
	Color map[16];
	for(i=0;i<16;++i)
		std::cin>>map[i].r>>map[i].g>>map[i].b;
	while(std::cin>>r>>g>>b&&r!=-1&&g!=-1&&b!=-1)
	{
		min=-1;
		j=-1;
		for(i=0;i<16;++i)
		{
			temp=(map[i].r-r)*(map[i].r-r)+
				(map[i].g-g)*(map[i].g-g)+
				(map[i].b-b)*(map[i].b-b);
			if(min<0||min>temp)
			{
				min=temp;
				j=i;
			}
		}
		std::cout<<"("<<r<<","<<g<<","<<b<<") maps to ("
			<<map[j].r<<","<<map[j].g<<","<<map[j].b<<")"<<std::endl;
	}
	
	return 0;
}  


Color Me Less

/*Color Me Less Language:DefaultColor Me Less Time Limit: 1000MS  Memory Limit: 10000K Total Sub...

zoj 1067 Color Me Less

正确代码: #include #include #include using namespace std; int main() { int tar[16][3]; for(int i=0;...

poj 1046 Color Me Less

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

POJ1046 Color Me Less(水题就当玩吧)

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31681   ...

POJ 1046(颜色映射 简单数学) 解题报告

POJ 1458(颜色映射 简单数学) 解题报告
  • masikkk
  • masikkk
  • 2011年03月21日 01:01
  • 1589

Solution of ZOJ 1067 Color Me Less

A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this ...
  • fduan
  • fduan
  • 2011年05月29日 19:21
  • 493

POJ 1046 Color Me Less

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31449   Accepted: 1...

poj1064 Color Me Less(枚举)

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30498   ...

Color Me Less

ACM之路

fjnu 1069 Color Me Less

DescriptionA color reduction is a mapping from a set of discrete colors to a smaller one. The soluti...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:1046 Color Me Less
举报原因:
原因补充:

(最多只允许输入30个字)