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. For循环语句的使用

    一.For循环语句 说明:For循环用于循环次数已经确定的情况下.  格式:for(循环变量赋初值; 循环条件; 循环变量增值)       {             ·····语句  } 举例:求 ...

  2. Android——五大布局

    Android的五大布局分为: 线性布局 相对布局 帧布局 绝对布局 表格布局 一.线性布局 线性布局在开发中使用最多,具有垂直方向与水平方向的布局方式 通过设置属性"android:ori ...

  3. 【转】c++中引用的全方位解读

    对于习惯使用C进行开发的朋友们,在看到c++中出现的&符号,可能会犯迷糊,因为在C语言中这个符号表示了取地址符,但是在C++中它却有着不同的用途,掌握C++的&符号,是提高代码执行效率 ...

  4. Web应用程序系统的多用户权限控制设计及实现-登录模块【4】

    通过前三个模块的介绍,把web权限系统开发所需要的基本类,Css文件,EasyUI框架等准备好后,就可以着手开始系统的编码了. 登陆模块是权限处理系统的关键,根据输入用户的的信息,可自动从数据库中加载 ...

  5. AFNetworking使用方法

    官网下载2.5版本:http://afnetworking.com/ 此文章是基于AFNetworking2.5版本的,需要看AFNetworking2.0版本的请看上一篇文章:AFNetworkin ...

  6. openstack 上床镜像, 创建网络, 创建虚拟机 命令

    ==================================================================================================== ...

  7. Effective Java 06 Eliminate obsolete object references

    NOTE Nulling out object references should be the exception rather than the norm. Another common sour ...

  8. 关于Redis中的Replication

    一.简介 Redis的replication机制允许slave从master那里通过网络传输拷贝到完整的数据备份.具有以下特点: 异步复制 可以配置一主多从 可以配置从服务器可以级联从服务器,既 M- ...

  9. 【nginx】常见的陷阱和错误

    很多人都可以碰到一个陷阱.下面我们列出,我们经常看到的问题,以及解释如何解决这些问题.在Freenode上的#nginx IRC频道这些讨论很频繁. 1.权限 从来不要使用777权限,查看目录的权限 ...

  10. node.js建立简单应用

    1. 建立工程 进入工程目录 cd D:\workspace\project 全局安装express,express作为命令被安装到了系统中 npm install -g express 查看expr ...