POJ1046 Color Me Less 水题

POJ1046 Color Me Less

Description
给出16行数字,再输入数据,找到前面16行数字中,与之距离最近的点。

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)

题解
整理ing

AC_Code(cpp):

#include<iostream>
using namespace std;
int temp[3];
int vis[16][3] = { 0 };
int solve(int a[])
{
    int s = (a[0] - temp[0])*(a[0] - temp[0]);
    s += (a[1] - temp[1])*(a[1] - temp[1]);
    s += (a[2] - temp[2])*(a[2] - temp[2]);
    return s;
}
int main()
{
    for (int i = 0; i < 16; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> vis[i][j];
        }
    }
    while (1)
    {
        for (int i = 0; i < 3; i++)
        {
            cin >> temp[i];
        }
        if (temp[0] == -1)
            break;
        int t = 0;
        int ans = solve(vis[0]);
        for (int i = 1; i < 16; i++)
        {
            if (ans>solve(vis[i]))
            {
                t = i;
                ans = solve(vis[i]);
            }
        }
        cout << "(" << temp[0] << "," << temp[1] << "," << temp[2] << ") maps to (" << vis[t][0] << "," << vis[t][1] << "," << vis[t][2] << ")" << endl;

    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值