Poj Solution 1046

http://poj.org/problem?id=1046

#include <stdio.h>
struct Color{
    int R,G,B;
}map[16];
int main() {
    int i;
    for ( i = 0; i < 16; ++i)
      scanf("%d%d%d",&map[i].R,&map[i].G,&map[i].B);
struct  Color c;
  while(scanf("%d%d%d",&c.R,&c.G,&c.B)&&c.R>=0){
        int index=0,min=65535;
         for ( i = 0; i < 16; ++i) {
            int d=(c.R-map[i].R)*(c.R-map[i].R)+
                    (c.G-map[i].G)*(c.G-map[i].G)+
                    (c.B-map[i].B)*(c.B-map[i].B);
            if(min>d){
                min=d;
                index=i;
            }
        }
        printf("(%d,%d,%d) maps to (",c.R,c.G,c.B);
        printf("%d,%d,%d)n",map[index].R,map[index].G,map[index].B);
  }

    return 0;
}

											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *