Source code for submission s621

Go to diff to previous submission

grasshop.cpp

  1. #include <stdio.h>
  2. #include <limits.h>
  3.  
  4. int ** ARRAY;
  5. int SIZEX;
  6. int SIZEY;
  7.  
  8. void jump(int X, int Y, int count)
  9. {
  10. if(X<0 || X>=SIZEX || Y<0 || Y>=SIZEY || count >= ARRAY[X][Y])
  11. return;
  12. ARRAY[X][Y]=count;
  13.  
  14. jump(X+1,Y+2, count+1);
  15. jump(X+2,Y+1, count+1);
  16. jump(X+2,Y-1, count+1);
  17. jump(X+1,Y-2, count+1);
  18. jump(X-1,Y-2, count+1);
  19. jump(X-2,Y-1, count+1);
  20. jump(X-2,Y+1, count+1);
  21. jump(X-1,Y+2, count+1);
  22.  
  23. }
  24.  
  25. int main()
  26. {
  27. int grex, grey, leafx, leafy;
  28.  
  29. while(scanf("%d %d %d %d %d %d\n", &SIZEX, &SIZEY, &grex, &grey, &leafx, &leafy)==6)
  30. {
  31. ARRAY=new int *[SIZEX];
  32. for (int i=0; i<SIZEX; i++)
  33. {
  34. ARRAY[i]=new int [SIZEY];
  35. for (int j=0; j<SIZEY; j++)
  36. {
  37. ARRAY[i][j]=INT_MAX;
  38. }
  39. }
  40. jump(grex-1,grey-1,0);
  41. if(ARRAY[leafx-1][leafy-1]==INT_MAX)
  42. printf("impossible\n");
  43. else printf("%d\n", ARRAY[leafx-1][leafy-1]);
  44. }
  45.  
  46. return 0;
  47. }
  48.  

Diff to submission s617

grasshop.cpp

--- 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;