Color Me Less
http://poj.org/problem?id=1046
View Code
#include<stdio.h> #include<math.h> int main() { int r[16], g[16], b[16] ; int i ; int x, y, z ; int min, s ; for(i=0; i<16; i++) scanf("%d%d%d",&r[i],&g[i],&b[i]) ; while(scanf("%d%d%d",&x,&y,&z)!=EOF) { if(x==-1&&y==-1&&z==-1) break ; min = (x-r[0])*(x-r[0]) + (y-g[0])*(y-g[0]) + (z-b[0])*(z-b[0]) ; int f = 0 ; for(i=1; i<16; i++) { s = (x-r[i])*(x-r[i]) + (y-g[i])*(y-g[i]) + (z-b[i])*(z-b[i]) ; if(s<min) { min = s ; f = i ; } } printf("(%d,%d,%d) maps to (%d,%d,%d)\n", x, y, z, r[f],g[f],b[f]) ; } return 0 ; }