Go to diff to previous submission
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> static int found; struct memo { char s[1000][1000]; int x; int y; int gx; int gy; }; void clean(struct memo *m) { } int isvisit(struct memo *m, int x, int y) { return (m->s[x][y] == 'q'); } void markr(struct memo *m, int x, int y) { #ifdef DEBUG #endif if (x >= m->x) return; if (y >= m->y) return; if (x < 0) return; if (y < 0) return; if (isvisit(m, x, y)) return; m->s[x][y] = 'r'; /* sleep (1); */ /* sleep (1); */ } void hop(struct memo *m, int x, int y) { #ifdef DEBUG #endif if (x >= m->x) return; if (y >= m->y) return; if (x < 0) return; if (y < 0) return; if (isvisit(m, x, y)) return; if (m->s[x][y] != 'r') return; m->s[x][y] = 'q'; if ((x == m->gx) && (y == m->gy)) { found = 1; return; } markr(m, x+1, y+2); markr(m, x+1, y-2); markr(m, x-1, y+2); markr(m, x-1, y-2); markr(m, x+2, y+1); markr(m, x+2, y-1); markr(m, x-2, y+1); markr(m, x-2, y-1); /* sleep (1); /* sleep (1); */ } int dohop(struct memo *m) { #ifdef DEBUG #endif int nnx[1000]; int nny[1000]; int off =0; /* start child in r-s*/ int ch = 0; int nx, ny; for (nx = 0; nx < m->x; nx++) { for (ny = 0; ny < m->y; ny++) { if (m->s[nx][ny] == 'r') { nnx[off] = nx; nny[off] = ny; off++; } if (found != 0) { /* found++; */ return 0; } } } int i; for (i = 0; i < off ; i++){ hop(m, nnx[i], nny[i]); } return off; } int main(void) { #ifdef DEBUG #endif unsigned int aa, ab, ba, bb, ca, cb; while (1){ found = 0; aa = ~0; if (aa == ~0) struct memo m; clean(&m); m.x = aa; m.y = ab; m.gx = ca-1; m.gy = cb-1; m.s[ba-1][bb-1] = 'r'; int count = 0; while (dohop(&m) && (found == 0)) {count++; #ifdef DEBUG #endif } if (found) { } else { } }}
--- c4.s879.cteam073.grasshop.c.0.greg.c +++ c4.s892.cteam073.grasshop.c.0.greg.c @@ -3,5 +3,5 @@ #include <unistd.h> - +#include <string.h> static int found; @@ -18,12 +18,5 @@ void clean(struct memo *m) { - int x; - int y; - for (x = 0; x < m->x; x++){ - for (y = 0; y < m->y; y++){ - m->s[x][y] = 'a'; - } - } - + memset(m->s, 'a', m->x * m->y * sizeof(char)); }