Color Me Less
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 32987   Accepted: 16037

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种色彩,称之为集合A,然后再输入N种色彩,这些色彩为集合B,遇到色彩为输入为-1,-1,-1时,结束输入。然后,要求从B到A有个映射,这个映射的距离最短,即为下面的公式的值最小

然后,按照标准格式输出。

分析:思路就是想用一个数组将B集合到A集合的映射的所有距离全部存起来,然后按照从小到大的顺序排序。当然,要先用另外一个数组保存一下原始的数组,用于后续的判断。注意题目中的一句话If there are more than one color with the same smallest distance, please output the color given first in the color set.如果有多个同样的距离,按照顺序输出第一个就好。所以在输出的过程中要注意循环的终止。

做这种题目思路多是如此。

 /*暴力枚举,没啥好讲的*/
#include<cstdio>
#include<cmath>
#include<iostream> using namespace std; int a[],b[],c[],x,y,z,n;
double d,s; int main()
{
for(int i=;i<;i++)
scanf("%d%d%d",&a[i],&b[i],&c[i]);
do
{
scanf("%d%d%d",&x,&y,&z);
if(x==-&&y==-&&z==-) break;
d=(x-a[])*(x-a[])+(y-b[])*(y-b[])+(z-c[])*(z-c[]);
n=;
for(int i=;i<;i++)
{
s=(x-a[i])*(x-a[i])+(y-b[i])*(y-b[i])+(z-c[i])*(z-c[i]);
if(s<d)
{
n=i;
d=s;
}
}
printf("(%d,%d,%d) maps to (%d,%d,%d)\n",x,y,z,a[n],b[n],c[n]);
}while();
return ;
}

poj 1046 ——Color Me Less的更多相关文章

  1. POJ 1046 Color Me Less 最详细的解题报告

    题目来源:POJ 1046 Color Me Less 题目大意:每一个颜色由R.G.B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ M ...

  2. poj 1046 Color Me Less

    Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33007   Accepted: 16050 D ...

  3. POJ 1046 Color Me Less(浅水)

    一.Description A color reduction is a mapping from a set of discrete colors to a smaller one. The sol ...

  4. [ACM] POJ 1046 Color Me Less

    Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30146   Accepted: 14634 D ...

  5. 组合数学 - 波利亚定理 --- poj : 2154 Color

    Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7873   Accepted: 2565 Description ...

  6. [ACM] POJ 2154 Color (Polya计数优化,欧拉函数)

    Color Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7630   Accepted: 2507 Description ...

  7. POJ 2054 Color a Tree

    贪心....                    Color a Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:  ...

  8. poj 2777Count Color

    http://poj.org/problem?id=2777 注意:a可能比b大 #include <cstdio> #include <cstring> #include & ...

  9. poj 2154 Color——带优化的置换

    题目:http://poj.org/problem?id=2154 置换的第二道题! 需要优化!式子是ans=∑n^gcd(i,n)/n (i∈1~n),可以枚举gcd=g,则有phi( n/g )个 ...

随机推荐

  1. Linux下C编写基本的多线程socket服务器

    不想多说什么,会搜这些东西的都是想看代码的吧. 一开始不熟悉多线程的时候还在想怎么来控制一个线程的结束,后来发现原来有pthread_exit()函数可以直接在线程函数内部调用结束这个线程. 开始还想 ...

  2. 城市安全风险管理项目Postmortem结果

    设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 本系统希望实现快速识别危害因素,使工作人员对风险作出准确的评估.即让使用者熟悉潜在的危险因素,知道 ...

  3. 【Swift】iOS裁剪或者压缩后出现的白边问题

    只需要将所有的CGFloat转化为NSInteger即可 func imageScaleSize(newSize: CGSize) -> UIImage{ let width = NSInteg ...

  4. JAVA_SE基础——36.static的实际应用

    什么时候定义静态函数 如果功能内部没有访问到非静态数据(对象的特有数据.那么该功能就可以定义为静态) P.S. 静态方法作为类和接口的重要组成部分,可以通过类名或接口直接访问,通常将那些使用频率较高的 ...

  5. Spring+Hibernate+Struts(SSH)框架整合

    SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...

  6. Table点击某个td获取当前列的头名称

    jq代码: $("td").click(function () { var tdHtml = $(this).attr("html"); var index = ...

  7. svn的使用技巧

    就是如果想一个文件在提交的时候不被上传,可以设置忽略这样提交的时候就不会被上传

  8. C++ 实现一个信号量

    C++ 实现一个信号量 信号量有很多应用场景,事实上只要是生产者-消费者模型,一般都需要一个信号量来控制. POSIX接口是有PV信号量API的.但C++标准没有.下面是一个PV信号量的简单实现.有些 ...

  9. c 语言常量

    1,整数常量 整数常量可以是十进制.八进制或十六进制的常量.前缀指定基数:0x 或 0X 表示十六进制,0 表示八进制,不带前缀则默认表示十进制. 整数常量也可以带一个后缀,后缀是 U 和 L 的组合 ...

  10. 3-51单片机WIFI学习(开发板8266底层源码介绍)

    上一篇链接  http://www.cnblogs.com/yangfengwu/p/8743502.html 直接上源码:注意源码有两部分,第一部分是一开始的时候写在模块内部的,另一部分是存在手机内 ...