2 * The Hobbling Horse Problem
4 * (c) 1996 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
14 signed char dist[MAX][MAX][2];
16 signed char queue[15*MAX*MAX];
18 int M, N, x0, y0, x1, y1;
20 struct delta { int dx, dy; };
22 struct delta king[] = { {-1,-1}, {0,-1}, {1,-1}, {-1,0}, {1,0}, {-1,1}, {0,1}, {1,1} };
23 struct delta horse[] = { {-1,-2}, {-1,2}, {-2,-1}, {2,-1}, {-2,1}, {2,1}, {1,-2}, {1,2} };
28 int qr, qw, x, y, z, k, xx, yy, rho;
31 memset(dist, 99, sizeof(dist));
46 k = sizeof(king) / sizeof(struct delta);
51 k = sizeof(horse) / sizeof(struct delta);
53 rho = dist[x][y][z] + 1;
59 if (xx >= 0 && xx < M && yy >= 0 && yy < N && dist[xx][yy][z] > rho)
61 dist[xx][yy][z] = rho;
74 int qr, qw, x, y, z, k, xx, yy, rho;
77 memset(dist, 99, sizeof(dist));
87 rho = dist[x][y][0] + 1;
92 k = sizeof(king) / sizeof(struct delta);
97 k = sizeof(horse) / sizeof(struct delta);
103 if (xx >= 0 && xx < M && yy >= 0 && yy < N && dist[xx][yy][0] > rho)
105 dist[xx][yy][0] = rho;
152 // printf("%d %d\n", x, y);
153 if (dist[x][y][0] > d++)
155 printf("BUG: %dx%d: %d.%d->%d.%d\n", M, N, x0, y0, x1, y1);
158 if (dlt(x, x1) <= lim && dlt(y, y1) <= lim)
160 if (dlt(x, x1) > dlt(y, y1))
198 // printf("%d %d\n", x, y);
199 if (dist[x][y][1] > d++)
201 printf("BUG: %dx%d: %d.%d->%d.%d\n", M, N, x0, y0, x1, y1);
204 if (dlt(x, x1) <= lim && dlt(y, y1) <= lim)
225 for(i=0; i<100000; i++)
233 printf("\n %dx%d: %d.%d->%d.%d\n", M, N, x0, y0, x1, y1);