1046 Color Me Less

来源:互联网 发布:demo制作软件 编辑:程序博客网 时间:2024/04/28 20:08

水题

  1. //4377084_AC_0MS_392K
  2. #include<iostream>
  3. #include<math.h>
  4. using namespace std;
  5. #define MAXINT 2147483647
  6. struct Color
  7. {
  8.     int r,g,b;
  9. };
  10. Color c[16];
  11. Color temp;
  12. inline double dis(Color x,Color y)
  13. {
  14.     return sqrt((double)(x.r-y.r)*(x.r-y.r)+(x.g-y.g)*(x.g-y.g)+(x.b-y.b)*(x.b-y.b));
  15. }
  16. int main()
  17. {
  18.     while(1)
  19.     {
  20.         for(int i=0;i<16;++i)
  21.         {
  22.             if(scanf("%d%d%d",&c[i].r,&c[i].g,&c[i].b)==-1) return 0;
  23.         }
  24.         while(1)
  25.         {
  26.             scanf("%d%d%d",&temp.r,&temp.g,&temp.b);
  27.             if(temp.r==-1&&temp.g==-1&&temp.b==-1)
  28.             {
  29.                 break;
  30.             }
  31.             double m=MAXINT;
  32.             int t;
  33.             for(int i=0;i<16;++i)
  34.             {
  35.                 double d=dis(temp,c[i]);
  36.                 if(d<m)
  37.                 {
  38.                     m=d;
  39.                     t=i;
  40.                 }
  41.             }
  42.             printf("(%d,%d,%d) maps to (%d,%d,%d)/n",temp.r,temp.g,temp.b,c[t].r,c[t].g,c[t].b);
  43.         }
  44.     }
  45.     return 0;
  46. }
原创粉丝点击