Color Me Less

Color Me Less

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Problem

A color reduction is a mapping from a set of discrete colors to a smaller one. The solution to this problem requires that you perform just such a mapping in a standard twenty-four bit RGB color space. The input consists of a target set of sixteen RGB color values, and a collection of arbitrary RGB colors to be mapped to their closest color in the target set. For our purposes, an RGB color is defined as an ordered triple (R,G,B) where each value of the triple is an integer from 0 to 255. The distance between two colors is defined as the Euclidean distance between two three-dimensional points. That is, given two colors (R1,G1,B1) and (R2,G2,B2), their distance D is given by the equation

 

 1 #include <iostream>
 2 #include <string>
 3 #include <algorithm>
 4 #include <map>
 5 #include <vector>
 6 #include <cstdio>
 7 #include <cmath>
 8 #include <cstring>
 9 using namespace std;
10 
11 int main()
12 {
13     int r[16], b[16], g[16];
14     for(int i = 0; i < 16; i++)
15     {
16         scanf("%d %d %d", r + i, g + i, b + i);
17     }
18     int x, y, z;
19     while(scanf("%d %d %d", &x, &y, &z))
20     {
21         if(x == -1 && y == -1 && z == -1) break;
22         double minD = (x - r[0]) * (x - r[0]) + (y - g[0])* (y - g[0]) + (z - b[0]) * (z - b[0]);
23         int id = 0;
24         for(int i = 1; i < 16; i++)
25         {
26             double D = (x - r[i]) * (x - r[i]) + (y - g[i]) * (y - g[i]) + (z - b[i]) * (z - b[i]);
27             if(minD > D)
28             {
29                 minD = D;
30                 id = i;
31             }
32         }
33         printf("(%d,%d,%d) maps to (%d,%d,%d)\n", x, y, z, r[id], g[id], b[id]);
34       //  cout << id << endl;
35     }
36     return 0;
37 }

 

转载于:https://www.cnblogs.com/cszlg/p/3246745.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值