POJ-1046
来源:互联网 发布:如何清除淘宝聊天记录 编辑:程序博客网 时间:2024/05/20 03:08
题目大意:
前16行 是用来作比较的数据,然后从17行开始,找与前16行距离最近的“距离”的值,
#include "stdio.h"#include "stdlib.h"#include "math.h"int a[15][3];int main(){int i;for(i=0;i<16;i++)scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);int r,g,b;while((scanf("%d%d%d",&r,&g,&b))!=EOF){int min=255*255*3;int tem=0;int temi=0;if(r==-1&&g==-1&&b==-1)break;elsefor(i=0;i<16;i++){tem=(a[i][0]-r)*(a[i][0]-r)+(a[i][1]-g)*(a[i][1]-g)+(a[i][2]-b)*(a[i][2]-b);if(tem<min){min=tem;temi=i;}}printf("(%d,%d,%d) maps to (%d,%d,%d)\n",r,g,b,a[temi][0],a[temi][1],a[temi][2]);}system("pause");return 0;}
注意:
1. min和tem和temi的复制要放在循环内,要不之前的结果会影响后面的结果,导致不正确
2. 在复制粘贴的时候尽量检查a[i][0],a[i][1],a[i][2]
0 0
- POJ-1046
- POJ 1046
- POJ 1046
- POJ-1046
- poj 1046
- poj 1046
- POJ-1046
- POJ-1046
- POJ 1046
- poj 1046
- POJ 1046 解题报告
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- Selenium2+Java环境搭建
- UML视图(四)状态图
- 优化算法——人工蜂群算法(ABC)
- COCOS2DX2.2.3遇到的奇葩问题记录
- UNIX环境高级编程(十二)线程控制
- POJ-1046
- 微信o2o的本地体验——王府井书店6层拍卖会上微信活动体验
- 编程之美---求二进制数中1的个数
- 交叉编译注意事项
- 2 Xcode5(5)
- 【分享】基于Gabor特征提取和人工智能神经网络的人脸检测matlab代码
- IE兼容模式X-UA-Compatible
- 百度之星 1003 Xor Sum
- 2014 传统生意转型年, 你准备好了吗?