POJ 1046

来源:互联网 发布:打蛋器价格淘宝 编辑:程序博客网 时间:2024/05/29 08:06
//实质就是让你求离在空间直角坐标系中某个给定的点的距离最近的那个点的坐标,即所谓的map(映射)

//注意:If there are more than one color with the same smallest distance,
//please output the color given first in the color set.

#include<iostream>
using namespace std;
int f(int a, int b, int c)
{
    return a*a + b*b + c*c;
}
struct color
{
    int R;
    int G;
    int B;
}c[16];
int main()
{
    int x, y, z, i, m, n, l,min;      //min记录所求的点的索引值(数组元素下标)
    for (i = 0; i < 16; i++)
    {
        cin >> x >> y >> z;
        c[i].R = x;
        c[i].G = y;
        c[i].B = z;
    }
    while (cin >> m >> n >> l&&!((m == -1) && (n == -1) && (l == -1)))
    {
        min = 0;
        for (i = 1; i < 16; i++)
        {
            if (f(m - c[i].R, n - c[i].G, l - c[i].B) < f(m - c[min].R, n - c[min].G, l - c[min].B)) min = i;
        }
        cout << "(" << m << "," << n << "," << l << ") maps to (" << c[min].R << "," << c[min].G << "," << c[min].B << ")\n";
    }
    return 0;
}
原创粉丝点击