Source code for submission s712

Go to diff to previous submission

grasshop.cpp

  1. #include <stdio.h>
  2. #define NOT_VISITED 2000
  3. using namespace std;
  4.  
  5. int main(){
  6. int W, H, SX, SY, EX, EY;
  7. int HX[8] = {1,1,-1,-1,2,2,-2,-2};
  8. int HY[8] = {2,-2,2,-2,1,-1,1,-1};
  9.  
  10.  
  11. while (scanf("%d %d %d %d %d %d", &W, &H, &SX, &SY, &EX, &EY) == 6){
  12. int QP = 0;
  13. int QL = 1;
  14. int QX[10010];
  15. int QY[10010];SX--;SY--;EX--;EY--;
  16. QX[0] = SX; QY[0] = SY;
  17. int field[102][102];
  18. for(int i = 0; i < W; i++){
  19. for(int j = 0; j < H; j++){
  20. field[i][j] = NOT_VISITED;
  21. }
  22. }
  23. field[SX][SY] = 0;
  24.  
  25. int can_finish = -1;
  26. while(QP < QL){
  27. for(int i = 0; i < 8; i++){
  28. int nx = QX[QP] + HX[i];
  29. int ny = QY[QP] + HY[i];
  30. if(nx >= 0 && ny >= 0 && nx < W && ny < H && field[nx][ny] == NOT_VISITED){
  31. field[nx][ny] = field[QX[QP]][QY[QP]] +1;
  32. QX[QL] = nx;
  33. QY[QL] = ny;
  34. QL++;
  35. }
  36.  
  37. }
  38. if(field[EX][EY] != NOT_VISITED){
  39. can_finish = field[EX][EY];
  40. break;
  41. }
  42. QP++;
  43. }
  44. if(can_finish > -1){
  45. printf("%d\n", can_finish);
  46. }else{
  47. printf("impossible\n");
  48. }
  49.  
  50. }
  51.  
  52.  
  53.  
  54. return 0;
  55. }
  56.  

Diff to submission s703

grasshop.cpp

--- c4.s703.cteam016.grasshop.cpp.0.grasshop.cpp
+++ c4.s712.cteam016.grasshop.cpp.0.grasshop.cpp
@@ -12,6 +12,6 @@
                 int QP = 0;
                 int QL = 1;
-                int QX[1010]; 
-                int QY[1010];SX--;SY--;EX--;EY--;
+                int QX[10010]; 
+                int QY[10010];SX--;SY--;EX--;EY--;
                 QX[0] = SX; QY[0] = SY;
                 int field[102][102];