poj 1046 ——Color Me Less
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 32987 | Accepted: 16037 |
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)
译文:
题意:先输入16种色彩,称之为集合A,然后再输入N种色彩,这些色彩为集合B,遇到色彩为输入为-1,-1,-1时,结束输入。然后,要求从B到A有个映射,这个映射的距离最短,即为下面的公式的值最小

然后,按照标准格式输出。
分析:思路就是想用一个数组将B集合到A集合的映射的所有距离全部存起来,然后按照从小到大的顺序排序。当然,要先用另外一个数组保存一下原始的数组,用于后续的判断。注意题目中的一句话If there are more than one color with the same smallest distance, please output the color given first in the color set.如果有多个同样的距离,按照顺序输出第一个就好。所以在输出的过程中要注意循环的终止。
做这种题目思路多是如此。
/*暴力枚举,没啥好讲的*/
#include<cstdio>
#include<cmath>
#include<iostream> using namespace std; int a[],b[],c[],x,y,z,n;
double d,s; int main()
{
for(int i=;i<;i++)
scanf("%d%d%d",&a[i],&b[i],&c[i]);
do
{
scanf("%d%d%d",&x,&y,&z);
if(x==-&&y==-&&z==-) break;
d=(x-a[])*(x-a[])+(y-b[])*(y-b[])+(z-c[])*(z-c[]);
n=;
for(int i=;i<;i++)
{
s=(x-a[i])*(x-a[i])+(y-b[i])*(y-b[i])+(z-c[i])*(z-c[i]);
if(s<d)
{
n=i;
d=s;
}
}
printf("(%d,%d,%d) maps to (%d,%d,%d)\n",x,y,z,a[n],b[n],c[n]);
}while();
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
Color Me Less Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33007 Accepted: 16050 D ...
- 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 )个 ...
随机推荐
- 听翁恺老师mooc笔记(14)--格式化的输入与输出
关于C语言如何做文件和底层操作: 文件操作,从根本上说,和C语言无关.这部分的内容,是教你如何使用C语言的标准库所提供的一系列函数来操作文件,最基本的最原始的文件操作.你需要理解,我们在这部分所学习的 ...
- bug终结者 团队作业第一周
bug终结者 团队作业第一周 小组组员及人员分工 小组成员 组长: 20162323 周楠 组员: 20162302 杨京典 20162322 朱娅霖 20162327 王旌含 20162328 蔡文 ...
- 进程与fork()、wait()、exec函数组
进程与fork().wait().exec函数组 内容简介:本文将引入进程的基本概念:着重学习exec函数组.fork().wait()的用法:最后,我们将基于以上知识编写Linux shell作为练 ...
- alpha-咸鱼冲刺day2
一,合照 emmmmm.自然是没有的. 二,项目燃尽图 三,项目进展 今天并没有什么进展,弄了好久好像也只研究出怎么把JS的功能块插入进去.html的信息提交这些还不知道要怎么弄. 四,问题困难 日常 ...
- DML数据操作语言之查询(一)
1.select语句基础 基本语句格式: select <列名>,.... from <表名>; select子句中列举出希望从表中查询出的列的名称,from子句则指定了选取 ...
- 数据恢复案例分享:MSSQL 2000 错误823
一.故障描述 MSSQL Server 2000 附加数据库错误823,附加数据库失败.数据库没有备份,不能通过备份恢复数据库,急需恢复数据库中的数据. 二.故障分析SQL Server数据库 823 ...
- java中DelayQueue的一个使用陷阱分析
最近工作中有接触到DelayQueue,网上搜索资料的时候发现一篇文章谈到DelayQueue的坑.点击打开链接 文中已经总结了遇到坑的地方,还有解决方案.不过我第一眼看一下没弄明白为什么,所以翻了翻 ...
- Java面试题(二)
系统整理了一下有关Java的面试题,包括基础篇,javaweb篇,框架篇,数据库篇,多线程篇,并发篇,算法篇等等,陆续更新中.其他方面如前端后端等等的面试题也在整理中,都会有的. 注:文末有福利! 1 ...
- LeetCode & Q189-Rotate Array-Easy
Array Description: Rotate an array of n elements to the right by k steps. For example, with n = 7 an ...
- ssl双向认证
ssl双向认证 一.背景知识 1.名词解释 ca.key: 根证书的私钥 , ca.crt: 根证书的签名证书 server.key, server.crt client.key, client.cr ...