Source code for submission s747

Go to diff to previous submission

grassshop.cpp

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int pole[100][100];
  5. int posSx, posSy;
  6. int posFx, posFy;
  7. int sizex, sizey;
  8.  
  9. void check(int x, int y, int jump)
  10. {
  11. if(jump > sizex * 3/2 && jump > sizey * 3/2)
  12. return;
  13. if(x > -1 && y > -1 && x < sizex && y < sizey)
  14. {
  15. if(pole[x][y]>jump)
  16. {
  17. pole[x][y] = jump;
  18. check(x+2, y+1,jump+1);
  19. check(x+2, y-1,jump+1);
  20. check(x-2, y+1,jump+1);
  21. check(x-2, y-1,jump+1);
  22. check(x+1, y+2,jump+1);
  23. check(x+1, y-2,jump+1);
  24. check(x-1, y+2,jump+1);
  25. check(x-1, y-2,jump+1);
  26. }
  27. }
  28.  
  29. }
  30.  
  31.  
  32. int main(void)
  33. {
  34.  
  35. while(scanf("%d %d %d %d %d %d", &sizex, &sizey, &posSx, &posSy, &posFx, &posFy) == 6)
  36. {
  37. for(int i = 0; i<sizex; i++)
  38. for(int j = 0; j<sizey; j++)
  39. pole[i][j] = 1000;
  40.  
  41. check(posSx-1, posSy-1, 0);
  42.  
  43.  
  44. if(pole[posFx-1][posFy-1]==1000)
  45. printf("impossible\n");
  46. else
  47. printf("%d\n", pole[posFx-1][posFy-1]);
  48. }
  49.  
  50. return 0;
  51.  
  52. }
  53.  

Diff to submission s720

grassshop.cpp

--- c4.s720.cteam107.grasshop.cpp.0.grassshop.cpp
+++ c4.s747.cteam107.grasshop.cpp.0.grassshop.cpp
@@ -9,4 +9,6 @@
 void check(int x, int y, int jump)
 {
+        if(jump > sizex * 3/2 && jump > sizey * 3/2)
+                return;
         if(x > -1 && y > -1 && x < sizex && y < sizey)
         {