Color Me Less(水题)
来源:互联网 发布:申万宏源软件中心 编辑:程序博客网 时间:2024/05/22 17:39
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 0255 255 2550 0 11 1 1128 0 00 128 0128 128 00 0 128
126 168 935 86 34133 41 193128 0 1280 128 128128 128 128255 0 00 1 00 0 0255 255 255253 254 25577 79 13481 218 0-1 -1 -1Sample 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)
题意:这相当于是在一个三维坐标里求点之间的最小距离。先输入十六个点,从第17行到文件结束 找每一行的点距离上面十六行距离最短的点 然后输出。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define inf 999999999
struct node
{
int r,g,b;
}cor1[16],cor2;
int main()
{
int i;
int dis,mdis;
int flag;
for(i=0;i<16;i++)
{
scanf("%d %d %d",&cor1[i].r,&cor1[i].g,&cor1[i].b);
}
while(1)
{
scanf("%d %d %d",&cor2.r,&cor2.g,&cor2.b);
mdis=inf;
if(cor2.r==-1&&cor2.g==-1&&cor2.b==-1)
break;
for(i=0;i<16;i++)
{
dis=(cor1[i].r-cor2.r)*(cor1[i].r-cor2.r)+(cor1[i].g-cor2.g)*(cor1[i].g-cor2.g)+(cor1[i].b-cor2.b)*(cor1[i].b-cor2.b);
if(mdis>dis)
{
mdis=dis;
flag=i;
}
}
printf("(%d,%d,%d) maps to (%d,%d,%d)\n",cor2.r,cor2.g,cor2.b,cor1[flag].r,cor1[flag].g,cor1[flag].b);}
return 0;}
- Color Me Less(水题)
- POJ1046 Color Me Less 水题
- poj1064 Color Me Less(枚举)
- POJ 1046 Color Me Less(水~)
- 1046 Color Me Less
- 1067 Color Me Less
- ZOJ1067 Color Me Less
- JOJ1090: Color Me Less
- 1046 Color Me Less
- 1046 Color Me Less
- acm1067-Color Me Less
- poj_1046 Color Me Less
- poj1046 color me less
- AOJ186 Color Me Less
- POJ1046;Color me less
- poj1046--Color Me Less
- Color Me Less
- Color Me Less
- 清除 thinkphp跟php的 X-Powered-By
- Android4.4电池管理
- Android listview动态添加删除更新带ProgressBar的Item
- js实现二级联动,并且可以设置任意初始省、市
- Win7下面安装SQL Server2005
- Color Me Less(水题)
- 视频会议的发展趋势---移动视频会议
- Unity3d中插入音频
- POJ3436 ACM Computer Factory 【最大流】
- Qt在Windows下的三种编程环境搭建
- SQL Server2005完全卸载
- 引用在链表中的应用
- IEEEVisWeek
- linux panic 问题定位