poj1046
来源:互联网 发布:cisco 不同端口访问 编辑:程序博客网 时间:2024/05/22 00:54
找出颜色相距最近的一个映射,
#include <iostream>
#include <cmath>
using namespace std;
struct rgb{
int r;
int g;
int b;
}color[17];
int dis(rgb &c1,rgb &c2){
int d=(int)sqrt((float)(c1.r-c2.r)*(c1.r-c2.r)+(float)(c1.g-c2.g)*(c1.g-c2.g)+(float)(c1.b-c2.b)*(c1.b-c2.b));
return d;
}
int main()
{
for(int i=0;i<16;i++)
scanf("%d%d%d",&color[i].r,&color[i].g,&color[i].b);
while(scanf("%d%d%d",&color[16].r,&color[16].g,&color[16].b)&&color[16].r!=-1){
int min=0x7fffffff,dist=0,ans;
for(int i=0;i<16;i++){
dist=dis(color[i],color[16]);
if(dist<min){
min=dist;
ans=i;
}
}
printf("(%d,%d,%d) maps to (%d,%d,%d)\n",color[16].r,color[16].g,color[16].b,color[ans].r,color[ans].g,color[ans].b);
}
return 0;
}
- POJ1046
- POJ1046
- poj1046
- poj1046
- poj1046
- poj1046
- POJ1046
- poj1046
- poj1046
- poj1046
- poj1046 枚举
- POJ1046解题报告
- POJ1046解题报告
- poj1046 枚举法
- poj1046 简单题
- 1poj1046(水题)
- poj1046 color me less
- POJ1046;Color me less
- [剑指offer]面试题40:数组中只出现一次的数字
- 如何用EWB画电路图
- iBATIS 相关操作
- 如何修改Window系统下PATH路径
- http://movie.douban.com/doulist/12002491/
- poj1046
- rsync+inotify同步的编译安装与配置
- 腾讯游戏分享汇:天天飞车六大研发经验
- Linux企业级项目实践之网络爬虫(8)——认识URL
- LeetCode 59 Restore IP Addresses
- Activity中需要重写的方法
- 机房收费系统之存储过程和触发器
- 什么事变量 和 变量定义的基础
- Java正则表达式