Source code for submission s871

Go to diff to previous submission

grasshop.cpp

  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. int dir[8][2] = {{1, 2}, {2, 1}, {2, -1}, {1, -2}, {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}};
  8.  
  9. struct point{
  10. point(int x_, int y_){x = x_; y = y_;}
  11. int x, y;
  12. };
  13.  
  14. int main(){
  15. int R, C, Sy, Sx, Cy, Cx;
  16. while(cin >> R >> C >> Sy >> Sx >> Cy >> Cx){
  17. if(Sy == Cy && Sx == Cx){
  18. cout << 0 << '\n';
  19. continue;
  20. }
  21. vector<vector<int> > pole(C+1, vector<int> (R+1));
  22. queue<point> Q;
  23. Q.push(point(Sx, Sy));
  24. while(!Q.empty()){
  25. point p = Q.front();
  26. Q.pop();
  27. for(int i=0; i<8; ++i){
  28. int x = p.x + dir[i][0];
  29. int y = p.y + dir[i][1];
  30. if(x > 0 && x <= C && y > 0 && y <= R){
  31. if(pole[x][y] == 0){
  32. Q.push(point(x, y));
  33. pole[x][y] = pole[p.x][p.y] + 1;
  34. if(x == Cx && y == Cy){
  35. cout << pole[x][y] << '\n';
  36. goto LOOP;
  37. }
  38. }
  39. }
  40. }
  41. }
  42. cout << "impossible\n";
  43. LOOP:;
  44.  
  45. }
  46. return 0;
  47. }
  48.  

Diff to submission s861

grasshop.cpp

--- c4.s861.cteam012.grasshop.cpp.0.grasshop.cpp
+++ c4.s871.cteam012.grasshop.cpp.0.grasshop.cpp
@@ -19,5 +19,5 @@
                         continue;
                 }
-                vector<vector<int> > pole(R+1, vector<int> (C+1));
+                vector<vector<int> > pole(C+1, vector<int> (R+1));
                 queue<point> Q;
                 Q.push(point(Sx, Sy));