#include #include #include #include typedef unsigned int uint; unsigned int map[1050000]; unsigned int d; unsigned int size[20]; unsigned int ps[20]; uint tpos[20]; uint spos[20]; uint mpos[20]; uint *stack; uint supersize; void recalc() { unsigned int t; ps[0] = 1; for (t=1;t 1) { a[dim]-=2; char val = get(a); if (val == target) { return l; } if (val == '.') { set(a, '*'); veccpy(&stack[spos*20],a); len[spos] = l; spos++; } a[dim]++; } else { a[dim]--; } } } return -1; } void go() { sizes(); recalc(); getchar(); unsigned int p[d]; readmap(p, d); p[0] = 0; p[1] = 0; /*unsigned int z; for (z = 0; z < 9; z++) { printf("%c",map[z]); } unsigned int s,t; for (s=0;s<3;s++) for (t=0;t<3;t++) { unsigned int v[d]; v[0] = s; v[1] = t; v[2] = 0; printf("%i %i : %u\n", s,t, pindex(v)); }*/ int vzd = 0, xx; xx = search(tpos, 'S'); if (xx == -1) { printf("No solution. Poor Theseus!\n"); return; }; vzd += xx; xx = search(spos, 'M'); if (xx == -1) { printf("No solution. Poor Theseus!\n"); return; }; vzd += xx; set(tpos, 'T'); xx = search(mpos, 'T'); if (xx == -1) { printf("No solution. Poor Theseus!\n"); return; }; vzd += xx; printf("Theseus needs %i steps.\n", vzd); } int main() { stack = malloc(sizeof(uint) * 20 * 1050000); for(;;) { scanf("%i\n",&d); if (d == 0) return 0; go(); } return 0; }