Web Colors UVALive - 7013(水题带公式)

题目链接:https://vjudge.net/problem/UVALive-7013

#include <bits/stdc++.h>
using namespace std;
string s[20] = {"White", "Silver","Gray", "Black", "Red", "Maroon", "Yellow", "Olive", "Lime", "Green", "Aqua", "Teal", "Blue", "Navy", "Fuchsia", "Purple"};
int A[20][3] = {{255,255,255},
                {192,192,192},
                {128,128,128},
                {0,0,0},
                {255,0,0},
                {128,0,0},
                {225,255,0},
                {128,128,0},
                {0,255,0},
                {0,128,0},
                {0,255,255},
                {0,128,128},
                {0,0,255},
                {0,0,128},
                {255,0,255},
                {128,0,128}
                };
int main(){
    int r, g, b;
    while(~scanf("%d%d%d", &r, &g, &b)){
        if(r == -1 && g == -1 && b == -1)
            break;
        int mini;
        double mind = 2147483647;
        for(int i = 0; i < 16; i++){
            double d = sqrt((A[i][0] - r)*(A[i][0] - r) + (A[i][1] - g)*(A[i][1] - g) + (A[i][2] - b)*(A[i][2] - b));
            if(d < mind){
                mind = d;
                mini = i;
            }
        }
        cout << s[mini] << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值