zoj 1067

输入一组RGB颜色列表,每行一个颜色,是三个从0~255的整数

前16行是目标颜色组,-1 -1 -1表示结束
 
16组颜色以后接下来的几行是需要判断的,看它和哪个颜色的距离D最小,找出这个对应的颜色
 
注意空格括弧等等
 
 1 #include<iostream>
 2 #include<math.h>
 3 using namespace std;
 4 
 5 struct Color
 6 {
 7     int R,G,B;
 8 }map[16];
 9 
10 int main(void)
11 {
12     int i,r,g,b,mr,mg,mb;
13     
14     
15     for(i=0;i<16;i++)
16     {
17         cin>>map[i].R>>map[i].G>>map[i].B;
18     }
19 
20     while(cin>>r>>g>>b&&(r!=-1)&&(g!=-1)&&(b!=-1))
21     {
22         int index = 0;
23         int min = 65535;
24 
25         for(i=0;i<16;i++)
26         {
27             int d = (r-map[i].R)*(r-map[i].R)+(g-map[i].G)*(g-map[i].G)+(b-map[i].B)*(b-map[i].B);
28             if(d<min)
29             {
30                 min = d;
31                 index = i;
32             }
33             
34         }
35        
36         cout<<"("<<r<<","<<g<<","<<b<<") maps to ("<<map[index].R<<","<<map[index].G<<","<<map[index].B<<")"<<endl;
37     }
38 
39     return 0;
40 }
原文地址:https://www.cnblogs.com/samjustin/p/4573643.html