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

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)

Source

 

先读懂题意

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

基本思路:

枚举,就OK了。

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int R[],G[],B[],r,g,b;
double cl(int r,int g,int b,int i){
return sqrt((double)(r-R[i])*(r-R[i])+(double)(g-G[i])*(g-G[i])+(double)(b-B[i])*(b-B[i]));
}
int main(){
for(int i=;i<=;i++){
cin>>R[i]>>G[i]>>B[i];
}
while(scanf("%d%d%d",&r,&g,&b)==&&r!=-&&g!=-&&b!=-){
int ans,flag=,minn=0x3f3f3f;
for(int i=;i<=;i++){
ans=cl(r,g,b,i);
if(ans<minn){
minn=ans;
flag=i;
}
}
printf("(%d,%d,%d) maps to (%d,%d,%d)\n",r,g,b,R[flag],G[flag],B[flag]);
}
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

    提交地址: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. javamail 发送邮件demo

    package com.suntray.test; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.M ...

  2. Android Studio 项目代码全部消失--出现原因及解决方法

    出现原因,自己把项目地址父层目录文件名修改了,导致原来打开的项目位置不对,代码全部消失.这样就只要关闭项目,打开一下你修改路径下的项目即可.因为原来的项目还在原来的路径下寻找,但是原来的路径发生了改变

  3. Android 优秀的开源框架整理

    第一部分:系统架构 thinkAndroid https://github.com/white-cat/ThinkAndroid ThinkAndroid是一个免费的开源的.简易的.遵循Apache2 ...

  4. E/AndroidRuntime(1636): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.***.app.wx.MainActivity} : android.view.InflateException: Binary XML file line #51 :

    类中加载的xml中,所自定义组件的包名错误(xml中51行错误:自定义组件包名写错了).

  5. OC中的内存问题

    常见的内存问题有以下几种: 1.野指针异常:访问没有所有权的内存,如果想要安全的访问,必须确保空间还在 2.内存泄露:空间使用完之后没有及时释放 3.过度释放:对同一块存储空间释放多次,立刻crash ...

  6. 软件工程(c编码实践) 学习笔记(一)

    vim 有三种模式:一般模式,编辑模式,命令模式. -------------------------------------------------------------------------- ...

  7. KVO的使用

    KVO的使用 KVO是一种设计模式,名为观察者. addObserver:forKeyPath:options:context: 通知其他对象的方法,这个方法在NSObject中就已经申明了,也就是说 ...

  8. Autocomplete:属性介绍、firefox中文支持问题

    如有问题,请前往 http://www.cnblogs.com/dreamowneryong/p/4953911.html 原文评论交流 一,属性介绍 * minChars (Number) 在触发a ...

  9. Spring-framework下载

    下载版本,修改版本号就行. http://repo.springsource.org/libs-release-local/org/springframework/spring/4.3.2.RELEA ...

  10. 解决 Eclipse 项目有红感叹号的方法

    原因:显示红色感叹号是因为jar包的路径不对 解决: 在项目上右击:Build Path -> Configure Build Paht...(或Propertise->Java Buil ...