C++代码
  1. /*  
  2. Title: Color Me Less    
  3. Problem URL: http://acm.zju.edu.cn/show_problem.php?pid=1067  
  4. Author: moqi  
  5. Date: 2008-02-08  
  6. Description: Accepted 1067 C++ 00:00.00 388K  
  7. */  
  8.   
  9. #include <stdlib.h>   
  10. #include <stdio.h>   
  11. int t[16][3];   
  12. int now[3];   
  13. int i, j;   
  14. long min, d;   
  15.   
  16. int main()   
  17. {   
  18. #ifdef ONLINE_JUDGE   
  19. #else   
  20.     freopen("1067.txt""r", stdin);   
  21. #endif   
  22.     for (i = 0; i < 16; i++)   
  23.     {   
  24.         scanf("%d %d %d", &t[i][0], &t[i][1], &t[i][2]);   
  25.     }   
  26.     while (scanf("%d %d %d", &now[0], &now[1], &now[2]) != -1)   
  27.     {   
  28.         if (now[0] == -1)   
  29.             break;   
  30.         min = 195075;   
  31.         j = 0;   
  32.         for (i = 0; i < 16; i++)   
  33.         {   
  34.             d = (long) (t[i][0] – now[0]) * (t[i][0] – now[0]) + (t[i][1] – now[1]) * (t[i][1] – now[1]) + (t[i][2] – now[2]) * (t[i][2] – now[2]);   
  35.             if (d < min)   
  36.             {   
  37.                 min = d;   
  38.                 j = i;   
  39.                 if (d == 0)   
  40.                     break;   
  41.             }   
  42.         }   
  43.         printf("(%d,%d,%d) maps to (%d,%d,%d)\n", now[0], now[1], now[2], t[j][0], t[j][1], t[j][2]);   
  44.     }   
  45. #ifdef ONLINE_JUDGE   
  46. #else   
  47.     fclose(stdin);   
  48. #endif   
  49.     return 0;   
  50. }