Go to diff to previous submission
#include <stdio.h> #include <limits.h> #include <iostream> int ** ARRAY; int SIZEX; int SIZEY; int MINCOUNT; int leafx, leafy; /* int min(int & X, int & Y) { if(X>Y) return Y; else return X; } */ void jump(int X, int Y, int count) { if(X==(leafx-1) && Y==(leafy-1)) { if(count < MINCOUNT) { ARRAY[X][Y]=count; MINCOUNT=count; } return; } if(X<0 || X>=SIZEX || Y<0 || Y>=SIZEY || count >= ARRAY[X][Y] || count>=MINCOUNT) 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; while(scanf("%d %d %d %d %d %d\n", &SIZEX, &SIZEY, &grex, &grey, &leafx, &leafy)==6) { MINCOUNT=INT_MAX; 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.s621.cteam009.grasshop.cpp.0.grasshop.cpp +++ c4.s653.cteam009.grasshop.cpp.0.grasshop.cpp @@ -1,13 +1,33 @@ #include <stdio.h> #include <limits.h> +#include <iostream> int ** ARRAY; int SIZEX; int SIZEY; - +int MINCOUNT; +int leafx, leafy; +/* +int min(int & X, int & Y) +{ + if(X>Y) return Y; + else return X; +} +*/ void jump(int X, int Y, int count) { -if(X<0 || X>=SIZEX || Y<0 || Y>=SIZEY || count >= ARRAY[X][Y]) +if(X==(leafx-1) && Y==(leafy-1)) +{ + if(count < MINCOUNT) + { + ARRAY[X][Y]=count; + MINCOUNT=count; + } + return; +} + +if(X<0 || X>=SIZEX || Y<0 || Y>=SIZEY || count >= ARRAY[X][Y] || count>=MINCOUNT) return; + ARRAY[X][Y]=count; @@ -25,8 +45,9 @@ int main() { - int grex, grey, leafx, leafy; + int grex, grey; while(scanf("%d %d %d %d %d %d\n", &SIZEX, &SIZEY, &grex, &grey, &leafx, &leafy)==6) { + MINCOUNT=INT_MAX; ARRAY=new int *[SIZEX]; for (int i=0; i<SIZEX; i++)