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. 1013团队Beta冲刺day6

    项目进展 李明皇 今天解决的进度 进行前后端联动调试 明天安排 完善程序运行逻辑 林翔 今天解决的进度 服务器端发布消息,删除消息,检索消息,个人发布的action 明天安排 图片功能遇到问题,微信小 ...

  2. 201621123050 《Java程序设计》第7周学习总结

    1. 本周学习总结 1.1 思维导图:Java图形界面总结 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模型中最重要的几个关键词. 1.事件:用户的操作,例如点击或输入之类的操作 2. ...

  3. 轻量级django 一

    from django.http import HttpResponse from django.conf.urls import url from django.conf import settin ...

  4. JAVA_SE基础——38.单例设计模式

    本文继续介绍23种设计模式系列之单例模式. 我们在javaSE的基础学习中,会讲到:单例设计模式.模板设计模式.装饰者设计模式.观察者设计模式.工厂设计模式 我以后随着水平的提高,我会专门开个分类写设 ...

  5. axure 预览"HTTP/1.1 302 Found"

    使用Axure编辑原型时,点击预览出现"HTTP/1.1 302 Found" 第一想到的就是重新安装Axure和检查原型文件是否损坏,验证后证明前Axure和.rp文件都是完好的 ...

  6. 从微软MVP到女儿开学--2017前半年小结

    2017年转眼就到了9月,原本在年初定的计划基本泡汤了. 看书啊减肥啊出教程啊,都被因为各种事物给缠身而没有完成. 1号带女儿去报名的时候,听到老师说"家长们请到这边来集合"的时候 ...

  7. Extensions in UWP Community Toolkit - Mouse Cursor

    概述 UWP Community Toolkit Extensions 中有一个为 Mouse 提供的扩展 - Mouse Cursor Extensions,本篇我们结合代码详细讲解 Mouse C ...

  8. javasciprt性能优化

    本文主要是在我读<高性能Javascript>之后,想要记录下一些有用的优化方案,并且就我本身的一些经验,来大家一起分享下, Javascript的加载与执行 大家都知道,浏览器在解析DO ...

  9. linux环境 安装chromedriver 和 phantomjs的方法

    1 首先要下载浏览器驱动: 常用的是chromedriver 和phantomjs chromedirver下载地址: https://npm.taobao.org/mirrors/chromedri ...

  10. mysql 查询select语句汇总

    数据准备: 创建表: create table students( id int unsigned primary key auto_increment not null, name varchar( ...