#include #include int main (void) { int k, K, s, i, j; int w, h, t; int x, y; int xx, yy, tt; int a[101][11][11]; int dd[101][11][11]; FILE *in = fopen ("sharks.in", "r"); fscanf (in, "%d\n", &K); for (k = 1; k <= K; k ++) { fscanf (in, "%d %d %d %d\n", &w, &h, &t, &s); for (tt = 1; tt <= t; tt ++) for (xx = 1; xx <= w; xx ++) for (yy = 1; yy <= h; yy ++) dd[tt][xx][yy] = 2*(w*w+h*h); for (i = 0; i < s; i ++) { fscanf (in, "%d %d %d\n", &x, &y, &tt); for (xx = 1; xx <= w; xx++) for (yy = 1; yy <= w; yy ++) if ((xx-x)*(xx-x) + (yy-y)*(yy-y) < dd[tt][xx][yy]) dd[tt][xx][yy] = (xx-x)*(xx-x) + (yy-y)*(yy-y); } for (xx = 1; xx <= w; xx ++) for (yy = 1; yy <= h; yy ++) a[1][xx][yy] = -2*(h*h+w*w); a[1][1][1] = dd[1][1][1]; for (tt = 2; tt <= t; tt ++) for (xx = 1; xx <= w; xx ++) for (yy = 1; yy <= h; yy ++) { int aa = a[tt-1][xx][yy]; if (xx > 1 && a[tt-1][xx-1][yy] > aa) aa = a[tt-1][xx-1][yy]; if (xx < w && a[tt-1][xx+1][yy] > aa) aa = a[tt-1][xx+1][yy]; if (yy > 1 && a[tt-1][xx][yy-1] > aa) aa = a[tt-1][xx][yy-1]; if (yy < h && a[tt-1][xx][yy+1] > aa) aa = a[tt-1][xx][yy+1]; if (dd[tt][xx][yy] < aa) aa = dd[tt][xx][yy]; a[tt][xx][yy] = aa; } printf ("Data Set %d:\n", k); printf ("%.2f\n", sqrt((double) a[t][1][1])); } fclose (in); return 0; }