PKU ACM 1046
2010-05-09 00:24
302 查看
题目:
Input
The input is a list of RGB colors, one color per line, specified as three integers from 0 to 255 delimited by a single space. The first sixteen colors form the target set of colors to which the remaining colors will be mapped. The input is terminated by a line containing three -1 values.
Output
For each color to be mapped, output the color and its nearest color from the target set.
If there are more than one color with the same smallest distance, please output the color given first in the color set.
Sample Input
Sample Output
Input
The input is a list of RGB colors, one color per line, specified as three integers from 0 to 255 delimited by a single space. The first sixteen colors form the target set of colors to which the remaining colors will be mapped. The input is terminated by a line containing three -1 values.
Output
For each color to be mapped, output the color and its nearest color from the target set.
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)
Answer:
#include <iostream> using std::cout ; using std::cin ; using std::endl ;
#include <cmath>
int main() { int a[16][3] = {0}; int b[100][3] = {0} ; int size = 0 ; int lowest = 65025 ; double result = 0 ; int index = 0 ;
for(int i=0 ;i<16;i++) { for(int j = 0 ; j<3 ;j++) { cin >> a[i][j] ; } }
for(int k = 0 ; ;k++) { for(int m = 0 ; m <3 ; m++) { cin >> b[k][m] ; } if(b[k][0]==-1&&b[k][1]==-1&&b[k][2]==-1) { break ; } size++ ;
} for(int p = 0 ; p < size ; p++) { for(int q = 0 ;q < 16 ;q++) { double temp = 0.0 ; temp = ((b[p][0]-a[q][0])*(b[p][0]-a[q][0])+(b[p][1]-a[q][1])*(b[p][1]-a[q][1])+(b[p][2]-a[q][2])*(b[p][2]-a[q][2])); result = sqrt(temp); if(result < lowest) { lowest = result ; index = q ; } } cout << "("<<b[p][0]<<","<<b[p][1]<<","<<b[p][2]<<") maps to ("<<a[index][0]<<","<<a[index][1]<<","<<a[index][2]<<")" << endl ; lowest = 65025 ; } return 0 ; }
相关文章推荐
- pku 1046 Color Me Less
- ACM PKU POJ 1112 解题报告
- http://acm.pku.edu.cn/JudgeOnline/problem?id=1284 (原根)
- http://acm.pku.edu.cn/JudgeOnline/problem?id=3667 区间更新+求满足长短的最左区间
- acm pku 1226 Substring的算法分析与实现
- PKU ACM 题目1018 源代码
- PKU ACM 1164 源代码
- PKU ACM-1019题 java Number Sequence
- ACM PKU POJ 1740 解题报告 -- 男人八题之四
- POJ 1004Financial Management解题报告——【PKU ACM】
- pku acm 1065
- [ACM] POJ 1046 Color Me Less
- PKU__ACM&nbsp;题目总结(转)
- Pku acm 1887 Testing the CATCHER 动态规划题目解题报告(十一)
- Pku acm 3253 Fence Repair 数据结构题目解题报告(一) ----哈夫曼数
- Pku acm 1611 The Suspects数据结构题目解题报告(九)---- 并查集的应用
- Pku acm 2371 Questions and answers 排序算法解题报告(三)----二叉查找数(BST)排序
- Pku acm 1423 Big Number 解题报告----求n!的位数
- acm pku 2234 解题报告(取子问题)
- acm pku 1088 滑雪