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

Input
Output
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的更多相关文章
- POJ 1046 Color Me Less 最详细的解题报告
题目来源:POJ 1046 Color Me Less 题目大意:每一个颜色由R.G.B三部分组成,D=Math.sqrt(Math.pow((left.red - right.red), 2)+ M ...
- poj 1046 ——Color Me Less
提交地址:http://poj.org/problem?id=1046 Color Me Less Time Limit: 1000MS Memory Limit: 10000K Total Su ...
- POJ 1046 Color Me Less(浅水)
一.Description A color reduction is a mapping from a set of discrete colors to a smaller one. The sol ...
- [ACM] POJ 1046 Color Me Less
Color Me Less Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30146 Accepted: 14634 D ...
- 组合数学 - 波利亚定理 --- poj : 2154 Color
Color Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7873 Accepted: 2565 Description ...
- [ACM] POJ 2154 Color (Polya计数优化,欧拉函数)
Color Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7630 Accepted: 2507 Description ...
- POJ 2054 Color a Tree
贪心.... Color a Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: ...
- poj 2777Count Color
http://poj.org/problem?id=2777 注意:a可能比b大 #include <cstdio> #include <cstring> #include & ...
- poj 2154 Color——带优化的置换
题目:http://poj.org/problem?id=2154 置换的第二道题! 需要优化!式子是ans=∑n^gcd(i,n)/n (i∈1~n),可以枚举gcd=g,则有phi( n/g )个 ...
随机推荐
- ABAP中正则表达式的简单使用方法 (转老白BLOG)
在一个论坛上面看到有人在问正则表达式的问题,特举例简单说明一下.另外,REPLACE也支持REGEX关键字.最后:只能是ECC6或者更高版本才可以(ABAP supports POSIX regula ...
- Win7 64位下sql server链接oracle的方法
继上一次mysql同步sql server后,这一次需要将Oracle同步到sql server上来,方案相似,只是在sql server链接oracle的时候费了很多时间. 一.测试环境 本方案实现 ...
- 详解Paint的setShader(Shader shader)
一.概述 setShader(Shader shader)中传入的自然是shader对象了,shader类是Android在图形变换中非常重要的一个类.Shader在三维软件中我们称之为着色器,其作用 ...
- 结合源代码详解android消息模型
Handler是整个消息系统的核心,是Handler向MessageQueue发送的Message,最后Looper也是把消息通知给Handler,所以就从Handler讲起. 一.Handler H ...
- 安卓第十四天笔记-内容提供者(ContentProvider)
安卓第十四天笔记-内容提供者(ContentProvider) ContentProvider--内容提供者 1.ContentProvider简介 ContentProvider是不同应用程序之间进 ...
- 【原】UIView实现点击着重效果的解决方案
我们知道,在IOS中UIButton UIControl都有一个默认的选中效果,即点中后会图标会变暗,移开后又恢复正常.如何让UIView UIImageView等这些普通的view也实现同样的效果呢 ...
- 【原】兼容IOS6以及旧版本的旋转处理方法,心得总结
最近的项目需要频繁处理屏幕的旋转以及各控件的自适应坐标.IOS6出来之后,屏幕旋转的处理方法变得复杂很多.在查阅了很多资料以及动手测试之后,得出以下几点精简的体会: 对于IOS6.0以上版本: 1.如 ...
- ASP.NET操作Cookie
1.生成Cookie public static void SetDataByCookie(string mainKey, string subKey, string value, string do ...
- device eth0 does not seem to be present, delaying initialization
在搭建LVS+Keepalived高可用负载均衡环境的过程中,使用VirtualBox复制了两个Centos的环境,并且选中了“重新初始化网卡”的选项,但是在启动这两个复制的Centos环境的时候,发 ...
- 【转】JAVA CAS原理深度分析
java.util.concurrent包完全建立在CAS之上的,没有CAS就不会有此包.可见CAS的重要性. CAS CAS:Compare and Swap, 翻译成比较并交换. java.uti ...