ZOJ1067: ColreMeLess (颜色压缩)

os posted @ 2013年9月09日 13:37 in ACM , 885 阅读

acm 题目List

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1067

 

#include <stdio.h>

struct color
{
	int R, G, B;
}map[16];

int main()
{
	int i = 0;
	for (i = 0; i < 16; i++)
		scanf("%d%d%d", &map[i].R, &map[i].G, &map[i].B);
	
	struct color c;
	while(scanf("%d%d%d", &c.R, &c.G, &c.B) && c.R >=0 )
	{
		int index = 0;
		int min = 65535;

		for (i = 0; i < 16; i++)
		{
			int d = (c.R - map[i].R)*(c.R - map[i].R) +
					(c.G - map[i].G)*(c.G - map[i].G) +
					(c.B - map[i].B)*(c.B - map[i].B);
			if (min > d)
			{
				min = d;
				index = i;
			}
		}

		printf("(%d,%d,%d) maps to ", c.R, c.G, c.B);
		printf("(%d,%d,%d)\n", map[index].R, map[index].G, map[index].B);
	}

	return 0;
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter