반응형
SMALL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include <stdio.h> // printf, scanf #include <string.h> int space[5][5][5] = { 0 }; int dist = 100000000; void checkDistance(int _i, int _j, int _k) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) { if (space[i][j][k] == 1) { if (i != _i || j != _j || k != _k) { int d = (i - _i)*(i - _i) + (j - _j)*(j - _j)+(k - _k)*(k - _k); if (dist > d) { dist = d; } } } } } } } int main(void) { int n; scanf("%d", &n); int x, y, z; for (int i = 0; i < n; i++) { scanf("%d %d %d", &x, &y, &z); space[x][y][z] = 1; } for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) { if (space[i][j][k] == 1) { // yes, there is mosquito!!! checkDistance(i, j, k); } } } } printf("%d", dist); return 0; } |
반응형
LIST