算法:枚舉
#include <iostream>
using namespace std;
int r,g,b;
int target[16][3];
int main()
{
double d, ans;
int key;
for (int i=0; i<16; i++)
{
cin >> target[i][0] >> target[i][1] >> target[i][2];
}
while (cin >> r >> g >> b)
{
if (r == -1 && g == -1 && b == -1)
{
break;
}
ans = 255*255*3+10;
for (int i=0; i<16; i++)
{
d = (target[i][0]-r)*(target[i][0]-r) + (target[i][1]-g)*(target[i][1]-g) + (target[i][2]-b)*(target[i][2]-b);
if (d < ans)
{
ans = d;
key = i;
}
}
cout << "(" << r << "," << g << "," << b << ") maps to (" << target[key][0] << "," << target[key][1] << "," << target[key][2] << ")" << endl;
}
}