题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=67
模拟。
#include<iostream> #include<cstdio> using namespace std; struct color { int R,G,B; }; int main() { color goal[16]; color col; for (int i=0; i<16; i++) cin>>goal[i].R>>goal[i].G>>goal[i].B; while (cin>>col.R>>col.G>>col.B && !(col.R == -1 && col.G == -1 && col.B ==-1)) { long long mind = (col.R-goal[0].R)*(col.R-goal[0].R)+ (col.G-goal[0].G)*(col.G-goal[0].G)+ (col.B-goal[0].B)*(col.B-goal[0].B); int pos = 0; for (int j=1; j<16; j++) { long long d = (col.R-goal[j].R)*(col.R-goal[j].R)+ (col.G-goal[j].G)*(col.G-goal[j].G)+ (col.B-goal[j].B)*(col.B-goal[j].B); if (d < mind) { mind = d; pos = j; } } printf("(%d,%d,%d) maps to (%d,%d,%d)\n",col.R,col.G,col.B,goal[pos].R,goal[pos].G,goal[pos].B); } return 0; }