Go to diff to previous submission
#include <stdio.h> #include <limits.h> int ** ARRAY; int SIZEX; int SIZEY; void jump(int X, int Y, int count) { if(X<0 || X>=SIZEX || Y<0 || Y>=SIZEY || count >= ARRAY[X][Y]) return; ARRAY[X][Y]=count; jump(X+1,Y+2, count+1); jump(X+2,Y+1, count+1); jump(X+2,Y-1, count+1); jump(X+1,Y-2, count+1); jump(X-1,Y-2, count+1); jump(X-2,Y-1, count+1); jump(X-2,Y+1, count+1); jump(X-1,Y+2, count+1); } int main() { int grex, grey, leafx, leafy; while(scanf("%d %d %d %d %d %d\n", &SIZEX, &SIZEY, &grex, &grey, &leafx, &leafy)==6) { ARRAY=new int *[SIZEX]; for (int i=0; i<SIZEX; i++) { ARRAY[i]=new int [SIZEY]; for (int j=0; j<SIZEY; j++) { ARRAY[i][j]=INT_MAX; } } jump(grex-1,grey-1,0); if(ARRAY[leafx-1][leafy-1]==INT_MAX) printf("impossible\n"); else printf("%d\n", ARRAY[leafx-1][leafy-1]); } return 0; }
--- c4.s617.cteam009.grasshop.cpp.0.grasshop.cpp +++ c4.s621.cteam009.grasshop.cpp.0.grasshop.cpp @@ -8,5 +8,5 @@ void jump(int X, int Y, int count) { -if(X<0 || X>=SIZEX || Y<0 || Y>=SIZEY || count > ARRAY[X][Y]) +if(X<0 || X>=SIZEX || Y<0 || Y>=SIZEY || count >= ARRAY[X][Y]) return; ARRAY[X][Y]=count;