Source code for submission s1230

Go to diff to previous submission

grasshop.c

  1. #include <stdio.h>
  2.  
  3. int width,height,fx,fy;
  4. int check[101][101];
  5.  
  6. void rek(int sx, int sy, int step)
  7. {
  8. static int stepX[] = {1, 2, 2, 1, -1, -2, -2, -1};
  9. static int stepY[] = {2, 1, -1, -2, -2, -1, 1, 2};
  10. int i, nextX, nextY;
  11.  
  12. check[sx][sy] = step;
  13. for(i=0; i<8; i++){
  14. nextX = sx + stepX[i];
  15. nextY = sy + stepY[i];
  16. if(nextX <= 0 || nextX > width) continue;
  17. if(nextY <= 0 || nextY > height) continue;
  18. if(check[nextX][nextY] > step+1)
  19. rek(nextX, nextY, step+1);
  20. }
  21.  
  22. return;
  23. }
  24.  
  25.  
  26. int main( int agrc, char * argv[] ) {
  27.  
  28. int sx,sy,i,j;
  29.  
  30. while( scanf("%d %d %d %d %d %d", &width,&height,&sx,&sy,&fx,&fy ) != EOF )
  31. {
  32. for (i=0; i<101;i++)
  33. for (j=0; j<101;j++)
  34. check[i][j]=50;
  35. rek(sx, sy, 0);
  36. if(check[fx][fy] == 50)
  37. printf("impossible\n");
  38. else
  39. printf("%d\n", check[fx][fy]);
  40.  
  41. }
  42.  
  43. return 0;
  44. }
  45.  

Diff to submission s1205

grasshop.c

--- c4.s1205.cteam043.grasshop.c.0.grasshop.c
+++ c4.s1230.cteam043.grasshop.c.0.grasshop.c
@@ -14,6 +14,6 @@
                 nextX = sx + stepX[i];
                 nextY = sy + stepY[i];
-                if(nextX < 0 || nextX >= width) continue;
-                if(nextY < 0 || nextY >= height) continue;              
+                if(nextX <= 0 || nextX > width) continue;
+                if(nextY <= 0 || nextY > height) continue;              
                 if(check[nextX][nextY] > step+1)
                         rek(nextX, nextY, step+1);
@@ -32,7 +32,7 @@
         for (i=0; i<101;i++)
                 for (j=0; j<101;j++)
-                        check[i][j]=200000000;  
+                        check[i][j]=50; 
         rek(sx, sy, 0);
-        if(check[fx][fy] == 200000000)
+        if(check[fx][fy] == 50)
                 printf("impossible\n");
         else