C++代码
- /*
- Title: Color Me Less
- Problem URL: http://acm.zju.edu.cn/show_problem.php?pid=1067
- Author: moqi
- Date: 2008-02-08
- Description: Accepted 1067 C++ 00:00.00 388K
- */
- #include <stdlib.h>
- #include <stdio.h>
- int t[16][3];
- int now[3];
- int i, j;
- long min, d;
- int main()
- {
- #ifdef ONLINE_JUDGE
- #else
- freopen("1067.txt", "r", stdin);
- #endif
- for (i = 0; i < 16; i++)
- {
- scanf("%d %d %d", &t[i][0], &t[i][1], &t[i][2]);
- }
- while (scanf("%d %d %d", &now[0], &now[1], &now[2]) != -1)
- {
- if (now[0] == -1)
- break;
- min = 195075;
- j = 0;
- for (i = 0; i < 16; i++)
- {
- 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]);
- if (d < min)
- {
- min = d;
- j = i;
- if (d == 0)
- break;
- }
- }
- 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]);
- }
- #ifdef ONLINE_JUDGE
- #else
- fclose(stdin);
- #endif
- return 0;
- }