关闭

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

标签: 水题
536人阅读 评论(0) 收藏 举报
分类:
Color Me Less
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 31681   Accepted: 15416

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)


解题思路:

好像是个大水题,就当睡前的愉快的最后一发好了,题意就是先给16个RGB的点,然后接着询问N个RGB点,求解询问的RGB点和16个中哪一个最近,公式已给,枚举就好,不过有个地方要小心,如果用pow的同学,别忘了它是有重载的,所以要明确你用的是哪个,有double,float和long double三个功能,最简单不会错的方法就是定义变量的时候都给它定义成double好了。睡觉去了。。

AC代码:

#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

double a[17][4]; //16个,3位
const double inf = 0xfffffff - 0.1;
 
int main()
{	
	int i;
	int rank;
	double d;
	double minx;
	double e,f,g;
	//freopen("1.txt","r",stdin);
	while(cin>>a[0][0]>>a[0][1]>>a[0][2])
	{
		for(i=1;i<16;i++)
		{
			cin>>a[i][0]>>a[i][1]>>a[i][2];
		}
		while(cin>>e>>f>>g && e != -1 && f != -1 && g != -1)
		{
			minx = inf;
			for(i=0;i<16;i++)
			{
				d = sqrt(pow(e-a[i][0],2)+ pow(f-a[i][1],2) + pow(g-a[i][2],2));
				//cout<<d<<endl;
				if(d < minx)
				{
					minx = d;
					rank = i;
					//cout<<rank<<endl;
				}
			}
			cout<<"("<<e<<","<<f<<","<<g<<")"<<" "<<"maps to ("<<a[rank][0]<<","<<a[rank][1]<<","<<a[rank][2]<<")"<<endl;
		}
	}
	return 0;
}
0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

教大家在网吧上网不用钱的办法

郑重声明:出现的一切后果自负! 本人不承担任何责任! 1、首先系统是XP的。(好象是废话,现在都用这种了) 第2步,关机再开机,这个过程最重要。手一定要一直按这F8键.这样子是强行进入系统。接着出来一...
  • linfenliang
  • linfenliang
  • 2014-09-18 16:17
  • 2449

LESS详解之混合(Mixins)高级

现在已经为大家介绍了LESS之混合(Mixins)的一些用法了,相信大家也用了不少有关LESS之混合(Mixins)了。接下来将为大家介绍一些有关LESS之混合(Mixins)的另外一些使用方法,可算...
  • LiMengXiaoLong
  • LiMengXiaoLong
  • 2013-11-06 09:02
  • 6124

NodeJS的安装以及Less编译器的安装调用

1、首先从官网https://nodejs.org/en/下载nodejs稳定版 ; 2、按步骤安装好; 3、打开电脑的cmd.exe; 4、输入node  -v 回车查看版本,然后输入npm  --...
  • St_Sp_En
  • St_Sp_En
  • 2017-02-22 21:17
  • 1750

POJ1046,Color Me Less,心情不爽就去切水

Color Me Less Description A color reduction is a mapping from a set of discrete colors to a sm...
  • Stand_over_sun
  • Stand_over_sun
  • 2012-11-19 21:24
  • 407

<poj 1046>Color Me Less

Color Me Less   Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25873 ...
  • cs_zlg
  • cs_zlg
  • 2012-07-14 12:02
  • 553

1046 poj Color Me Less

题意:匹配距离最小的两组数,先给你16个数据,然后再输入数据直到输入三个-1结束输入            把后输入的数据与前16个数据进行匹配,如果他们之间的距离在所有数据匹配中最小  ...
  • Tdreamge
  • Tdreamge
  • 2012-04-09 18:30
  • 460

POJ 1046-Color Me Less【暴力】

A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this ...
  • qq_29600137
  • qq_29600137
  • 2016-03-03 14:31
  • 212

poj 1046(Color Me Less)

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23677   ...
  • ll365594480
  • ll365594480
  • 2011-09-12 22:36
  • 227

POJ1046——Color Me Less

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33605   ...
  • LDUtyk
  • LDUtyk
  • 2016-11-15 15:46
  • 198

POJ 1046 Color Me Less

Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31449   Accepted: 1...
  • u013068502
  • u013068502
  • 2015-04-10 20:55
  • 386
    个人资料
    • 访问:72859次
    • 积分:2459
    • 等级:
    • 排名:第17261名
    • 原创:178篇
    • 转载:15篇
    • 译文:0篇
    • 评论:6条
    最新评论