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

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

  1. 0 0 0
  2. 255 255 255
  3. 0 0 1
  4. 1 1 1
  5. 128 0 0
  6. 0 128 0
  7. 128 128 0
  8. 0 0 128
  9. 126 168 9
  10. 35 86 34
  11. 133 41 193
  12. 128 0 128
  13. 0 128 128
  14. 128 128 128
  15. 255 0 0
  16. 0 1 0
  17. 0 0 0
  18. 255 255 255
  19. 253 254 255
  20. 77 79 134
  21. 81 218 0
  22. -1 -1 -1

Sample Output

  1. (0,0,0) maps to (0,0,0)
  2. (255,255,255) maps to (255,255,255)
  3. (253,254,255) maps to (255,255,255)
  4. (77,79,134) maps to (128,128,128)
  5. (81,218,0) maps to (126,168,9)

Source

 

先读懂题意

很简单,就是给定一个三维点以及一个由16个三维点组成的点集,求这个给定三维点与点集中哪个三维坐标点的距离最小。

基本思路:

枚举,就OK了。

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cmath>
  4. using namespace std;
  5. int R[],G[],B[],r,g,b;
  6. double cl(int r,int g,int b,int i){
  7. return sqrt((double)(r-R[i])*(r-R[i])+(double)(g-G[i])*(g-G[i])+(double)(b-B[i])*(b-B[i]));
  8. }
  9. int main(){
  10. for(int i=;i<=;i++){
  11. cin>>R[i]>>G[i]>>B[i];
  12. }
  13. while(scanf("%d%d%d",&r,&g,&b)==&&r!=-&&g!=-&&b!=-){
  14. int ans,flag=,minn=0x3f3f3f;
  15. for(int i=;i<=;i++){
  16. ans=cl(r,g,b,i);
  17. if(ans<minn){
  18. minn=ans;
  19. flag=i;
  20. }
  21. }
  22. printf("(%d,%d,%d) maps to (%d,%d,%d)\n",r,g,b,R[flag],G[flag],B[flag]);
  23. }
  24. return ;
  25. }

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

    提交地址:http://poj.org/problem?id=1046 Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  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. ABAP中正则表达式的简单使用方法 (转老白BLOG)

    在一个论坛上面看到有人在问正则表达式的问题,特举例简单说明一下.另外,REPLACE也支持REGEX关键字.最后:只能是ECC6或者更高版本才可以(ABAP supports POSIX regula ...

  2. Win7 64位下sql server链接oracle的方法

    继上一次mysql同步sql server后,这一次需要将Oracle同步到sql server上来,方案相似,只是在sql server链接oracle的时候费了很多时间. 一.测试环境 本方案实现 ...

  3. 详解Paint的setShader(Shader shader)

    一.概述 setShader(Shader shader)中传入的自然是shader对象了,shader类是Android在图形变换中非常重要的一个类.Shader在三维软件中我们称之为着色器,其作用 ...

  4. 结合源代码详解android消息模型

    Handler是整个消息系统的核心,是Handler向MessageQueue发送的Message,最后Looper也是把消息通知给Handler,所以就从Handler讲起. 一.Handler H ...

  5. 安卓第十四天笔记-内容提供者(ContentProvider)

    安卓第十四天笔记-内容提供者(ContentProvider) ContentProvider--内容提供者 1.ContentProvider简介 ContentProvider是不同应用程序之间进 ...

  6. 【原】UIView实现点击着重效果的解决方案

    我们知道,在IOS中UIButton UIControl都有一个默认的选中效果,即点中后会图标会变暗,移开后又恢复正常.如何让UIView UIImageView等这些普通的view也实现同样的效果呢 ...

  7. 【原】兼容IOS6以及旧版本的旋转处理方法,心得总结

    最近的项目需要频繁处理屏幕的旋转以及各控件的自适应坐标.IOS6出来之后,屏幕旋转的处理方法变得复杂很多.在查阅了很多资料以及动手测试之后,得出以下几点精简的体会: 对于IOS6.0以上版本: 1.如 ...

  8. ASP.NET操作Cookie

    1.生成Cookie public static void SetDataByCookie(string mainKey, string subKey, string value, string do ...

  9. device eth0 does not seem to be present, delaying initialization

    在搭建LVS+Keepalived高可用负载均衡环境的过程中,使用VirtualBox复制了两个Centos的环境,并且选中了“重新初始化网卡”的选项,但是在启动这两个复制的Centos环境的时候,发 ...

  10. 【转】JAVA CAS原理深度分析

    java.util.concurrent包完全建立在CAS之上的,没有CAS就不会有此包.可见CAS的重要性. CAS CAS:Compare and Swap, 翻译成比较并交换. java.uti ...