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. Android 五大布局

    Android 五大布局:  FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),Table ...

  2. Oracle数据库中创建表空间语句

    1:创建临时表空间 create temporary tablespace user_temp tempfile 'Q:\oracle\product\10.2.0\oradata\Test\xyrj ...

  3. SarePoint Powershell Add user to Group

    $FromGroupnames = "001总经理","010101管理本部" $ToGroupname = "test" $SPWeb = ...

  4. [转] X-RIME: 基于Hadoop的开源大规模社交网络分析工具

    转自http://www.dataguru.cn/forum.php?mod=viewthread&tid=286174 随着互联网的快速发展,涌现出了一大批以Facebook,Twitter ...

  5. Android 开关按钮切换,类似于iphone 效果,view实现

    1.实现的效果 gitHub :  https://github.com/zcweng/ToggleButton

  6. xCode删除storyboard,新建window并启动

    application:didFinishLaunchingWithOptions该函数是应用程序启动之后首次加载页面的函数,删除storyboard之后,需要在这里new出新的window,初始化, ...

  7. iOS设计模式之原型模式

    原型模式 基本理解 原型模式(Prototype),用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 原型模式其实就是从一个对象再创建另外一个可定制的对象,而且不需要知道任何创建的细节 ...

  8. 【改】IOS-百度地图API用点生成线路、导航、自定义标注 2013年11月更新

    IOS百度地图API开发自定义气泡,点击气泡自动生成路线,以及拖拽IOS百度地图开发POISearch搜索附近停车场,附近加油站IOS百度地图视角跳到用户当前位置IOS百度地图开发实时路况IOS开发百 ...

  9. Gleeo Time Tracker简明使用教程

    转载一篇很不错的文章,这款软件还是非常实用的 1 简介 Gleeo Time Tracker是安卓平台下一款相当酷的项目时间记录和管理的软件.说他酷,是因为界面纯黑.而除了这点酷之外,功能也很简单实用 ...

  10. c++基础回顾

    #include <iostream> #include <vector> #include <string> int main(int argc, const c ...