Source code for submission s1055

Go to diff to previous submission

main.cpp

  1. #define PROJECT 4
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <queue>
  6. #include <limits>
  7.  
  8. typedef unsigned long long ull;
  9.  
  10. using namespace std;
  11.  
  12. #if PROJECT == 1
  13.  
  14.  
  15. int main() {
  16. int l, a;
  17.  
  18. while (cin >> l >> a) {
  19. int pos;
  20. char dir;
  21. cin >> pos >> dir;
  22.  
  23. }
  24. }
  25.  
  26. #elif PROJECT == 2
  27. #elif PROJECT == 3
  28. #elif PROJECT == 4
  29.  
  30.  
  31. int main() {
  32. int r, s, gr, gs, lr, ls;
  33.  
  34. int grid[105][105]; //inicializovat este!
  35.  
  36. vector< pair<int,int> > moves;
  37. moves.push_back(make_pair(1,2));
  38. moves.push_back(make_pair(1,-2));
  39. moves.push_back(make_pair(-1,2));
  40. moves.push_back(make_pair(-1,-2));
  41. moves.push_back(make_pair(2,1));
  42. moves.push_back(make_pair(2,-1));
  43. moves.push_back(make_pair(-2,1));
  44. moves.push_back(make_pair(-2,-1));
  45.  
  46. queue< pair<int,int> > todo;
  47.  
  48. while(cin >> r >> s >> gr >> gs >> lr >> ls)
  49. {
  50. for (int i=0; i<103; i++)
  51. for (int j=0; j<103; j++)
  52. grid[i][j]=-1;
  53.  
  54. pair<int,int> leaf = make_pair(lr,ls);
  55.  
  56. todo.push(make_pair(gr,gs));
  57. grid[gr][gs]=0;
  58.  
  59. while(!todo.empty()){
  60.  
  61. pair<int,int> current = todo.front();
  62. todo.pop();
  63.  
  64. for(vector< pair<int,int> >::iterator i = moves.begin(); i!=moves.end();i++)
  65. {
  66. pair<int,int> next = make_pair(current.first+i->first,current.second+i->second);
  67.  
  68. if(next.first >= 1 && next.first <= r && next.second >= 1 && next.second <= s){
  69. if(grid[next.first][next.second]==-1) {
  70. grid[next.first][next.second]=grid[current.first][current.second]+1;
  71. if(next==leaf) {
  72. cout << grid[next.first][next.second] << endl;
  73. }
  74. todo.push(next);
  75. }
  76. }
  77. }
  78. }
  79.  
  80. if(grid[leaf.first][leaf.second]==-1) cout << "impossible" << endl;
  81. //1==1;
  82. }
  83.  
  84.  
  85. }
  86.  
  87. #elif PROJECT == 5
  88.  
  89. #elif PROJECT == 6
  90.  
  91. int main() {
  92.  
  93. unsigned long long m, p, l, e ,r, s, n;
  94.  
  95. while (cin >> m >> p >> l >> e >> r >> s >> n) {
  96. for (ull i = 0; i < n; i++) {
  97. ull m1, p1, l1;
  98. m1 = p / s;
  99. p1 = l / r;
  100. l1 = m * e;
  101.  
  102. m = m1; p = p1; l = l1;
  103. }
  104. cout << m << endl;
  105. }
  106.  
  107. return 0;
  108. }
  109.  
  110. #endif
  111.  

Diff to submission s985

main.cpp

--- c4.s985.cteam098.grasshop.cpp.0.main.cpp
+++ c4.s1055.cteam098.grasshop.cpp.0.main.cpp
@@ -28,94 +28,59 @@
 #elif PROJECT == 4
 
-struct task {
-    int x, y;
-    task(int _x, int _y) : x(_x), y(_y) {}
-};
 
-int grid[100][100];
+int main() {
+    int r, s, gr, gs, lr, ls;
 
-const int INF = /* numeric_limits<int>::max() - 1;*/ 100000;
+    int grid[105][105]; //inicializovat este!
 
-int r, c, gr, gc, lr, lc;
-void dump() {
-    for (int i = 0; i < r; i++) {
-        for (int j = 0; j < c; j++ ) {
-            cout << '\t' << (grid[i][j]);
-        }
-        endl(cout);
-    }
-}
+    vector< pair<int,int> > moves;
+    moves.push_back(make_pair(1,2));
+    moves.push_back(make_pair(1,-2));
+    moves.push_back(make_pair(-1,2));
+    moves.push_back(make_pair(-1,-2));
+    moves.push_back(make_pair(2,1));
+    moves.push_back(make_pair(2,-1));
+    moves.push_back(make_pair(-2,1));
+    moves.push_back(make_pair(-2,-1));
 
-int main() {
-    while (cin >> r >> c >> gr >> gc >> lr >> lc) {
-        //endl(cout);
-        //cout << "#############################################################" << endl << endl;
-        for (int i = 0; i < r; i++ ) {
-            for (int j = 0; j < c; j++) {
-                grid[i][j] = INF;
-            }
-        }
-        gr--, gc--, lr--, lc--;
-        bool flag = false;
-        grid[gr][gc] = 0;
-        queue<task> todo;
-        todo.push(task(gr, gc));
+    queue< pair<int,int> > todo;
 
-        while (!todo.empty() || flag) {
-            task current = todo.front(); todo.pop();
-           //cout << "************************" << endl;
-           // dump();
+    while(cin >> r >> s >> gr >> gs >> lr >> ls)
+    {
+        for (int i=0; i<103; i++)
+            for (int j=0; j<103; j++)
+                grid[i][j]=-1;
 
-            for (int i = -2; i <= 2; i++) {
-                if (i == 0 || current.x + i < 0 || current.x + i > c - 1) continue;
+        pair<int,int> leaf = make_pair(lr,ls);
 
-                if (abs(i) == 1) {
-                    for (int j = -2; j <= 2; j += 4) {
-                        if (current.y + j < 0 || current.y + j > r -  1) continue;
+        todo.push(make_pair(gr,gs));
+        grid[gr][gs]=0;
 
-                        int tx = current.x + i;
-                        int ty = current.y + j;
-                        if (grid[tx][ty] == INF) {
-                            grid[tx][ty] = grid[current.x][current.y] + 1;
-                            todo.push(task(tx, ty));
-                            if ((lr == tx) & (lc == ty))
-                                flag   == true;
-                        }
+        while(!todo.empty()){
 
-                    }
-                } else if (abs(i) == 2) {
+            pair<int,int> current = todo.front();
+            todo.pop();
 
-                    for (int j = -1; j <= 1; j += 2) {
-                        if (current.y + j < 0 || current.y + j > r -  1) continue;
+            for(vector< pair<int,int> >::iterator i = moves.begin(); i!=moves.end();i++)
+            {
+                pair<int,int> next = make_pair(current.first+i->first,current.second+i->second);
 
-                        int tx = current.x + i;
-                        int ty = current.y + j;
-                        if (grid[tx][ty] == INF) {
-                            grid[tx][ty] = grid[current.x][current.y] + 1;
-                            todo.push(task(tx, ty));
-                            if ((lr == tx) & (lc == ty))
-                               flag == true;
+                if(next.first >= 1 && next.first <= r && next.second >= 1 && next.second <= s){
+                    if(grid[next.first][next.second]==-1) {
+                        grid[next.first][next.second]=grid[current.first][current.second]+1;
+                        if(next==leaf) {
+                            cout << grid[next.first][next.second] << endl;
                         }
+                        todo.push(next);
                     }
-                }else {
-                    //cerr << "dafuq?" << endl;
                 }
             }
+            }
 
-
-        }
-
-        //  cout << "&&&&&&&&&&" << endl;
-
-        if (grid[lr][lc] == INF) {
-            cout << "impossible" << endl;
-
-        } else {
-            cout << grid[lr][lc] << endl;
-        }
-
+        if(grid[leaf.first][leaf.second]==-1) cout << "impossible" << endl;
+        //1==1;
     }
 
-    return 0;
+
 }