Source code for submission s985

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. struct task {
  31. int x, y;
  32. task(int _x, int _y) : x(_x), y(_y) {}
  33. };
  34.  
  35. int grid[100][100];
  36.  
  37. const int INF = /* numeric_limits<int>::max() - 1;*/ 100000;
  38.  
  39. int r, c, gr, gc, lr, lc;
  40. void dump() {
  41. for (int i = 0; i < r; i++) {
  42. for (int j = 0; j < c; j++ ) {
  43. cout << '\t' << (grid[i][j]);
  44. }
  45. endl(cout);
  46. }
  47. }
  48.  
  49. int main() {
  50. while (cin >> r >> c >> gr >> gc >> lr >> lc) {
  51. //endl(cout);
  52. //cout << "#############################################################" << endl << endl;
  53. for (int i = 0; i < r; i++ ) {
  54. for (int j = 0; j < c; j++) {
  55. grid[i][j] = INF;
  56. }
  57. }
  58. gr--, gc--, lr--, lc--;
  59. bool flag = false;
  60. grid[gr][gc] = 0;
  61. queue<task> todo;
  62. todo.push(task(gr, gc));
  63.  
  64. while (!todo.empty() || flag) {
  65. task current = todo.front(); todo.pop();
  66. //cout << "************************" << endl;
  67. // dump();
  68.  
  69. for (int i = -2; i <= 2; i++) {
  70. if (i == 0 || current.x + i < 0 || current.x + i > c - 1) continue;
  71.  
  72. if (abs(i) == 1) {
  73. for (int j = -2; j <= 2; j += 4) {
  74. if (current.y + j < 0 || current.y + j > r - 1) continue;
  75.  
  76. int tx = current.x + i;
  77. int ty = current.y + j;
  78. if (grid[tx][ty] == INF) {
  79. grid[tx][ty] = grid[current.x][current.y] + 1;
  80. todo.push(task(tx, ty));
  81. if ((lr == tx) & (lc == ty))
  82. flag == true;
  83. }
  84.  
  85. }
  86. } else if (abs(i) == 2) {
  87.  
  88. for (int j = -1; j <= 1; j += 2) {
  89. if (current.y + j < 0 || current.y + j > r - 1) continue;
  90.  
  91. int tx = current.x + i;
  92. int ty = current.y + j;
  93. if (grid[tx][ty] == INF) {
  94. grid[tx][ty] = grid[current.x][current.y] + 1;
  95. todo.push(task(tx, ty));
  96. if ((lr == tx) & (lc == ty))
  97. flag == true;
  98. }
  99. }
  100. }else {
  101. //cerr << "dafuq?" << endl;
  102. }
  103. }
  104.  
  105.  
  106. }
  107.  
  108. // cout << "&&&&&&&&&&" << endl;
  109.  
  110. if (grid[lr][lc] == INF) {
  111. cout << "impossible" << endl;
  112.  
  113. } else {
  114. cout << grid[lr][lc] << endl;
  115. }
  116.  
  117. }
  118.  
  119. return 0;
  120. }
  121.  
  122. #elif PROJECT == 5
  123.  
  124. #elif PROJECT == 6
  125.  
  126. int main() {
  127.  
  128. unsigned long long m, p, l, e ,r, s, n;
  129.  
  130. while (cin >> m >> p >> l >> e >> r >> s >> n) {
  131. for (ull i = 0; i < n; i++) {
  132. ull m1, p1, l1;
  133. m1 = p / s;
  134. p1 = l / r;
  135. l1 = m * e;
  136.  
  137. m = m1; p = p1; l = l1;
  138. }
  139. cout << m << endl;
  140. }
  141.  
  142. return 0;
  143. }
  144.  
  145. #endif
  146.  

Diff to submission s693

main.cpp

--- c4.s693.cteam098.grasshop.cpp.0.main.cpp
+++ c4.s985.cteam098.grasshop.cpp.0.main.cpp
@@ -35,33 +35,52 @@
 int grid[100][100];
 
+const int INF = /* numeric_limits<int>::max() - 1;*/ 100000;
+
+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);
+    }
+}
+
 int main() {
-    int r, c, gr, gc, lr, lc;
     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] = numeric_limits<int>::max();
+                grid[i][j] = INF;
             }
         }
         gr--, gc--, lr--, lc--;
+        bool flag = false;
         grid[gr][gc] = 0;
         queue<task> todo;
         todo.push(task(gr, gc));
 
-        while (!todo.empty()) {
-            task next = todo.front(); todo.pop();
+        while (!todo.empty() || flag) {
+            task current = todo.front(); todo.pop();
+           //cout << "************************" << endl;
+           // dump();
 
             for (int i = -2; i <= 2; i++) {
-                if (i == 0 || next.x + i < 0 || next.x + i > c - 1) continue;
+                if (i == 0 || current.x + i < 0 || current.x + i > c - 1) continue;
 
                 if (abs(i) == 1) {
                     for (int j = -2; j <= 2; j += 4) {
-                        if (next.y + j < 0 || next.y + j > r -  1) continue;
+                        if (current.y + j < 0 || current.y + j > r -  1) continue;
 
-                        int tx = next.x + i;
-                        int ty = next.y + j;
-                        if (grid[ty][tx] > grid[next.y][next.x] + 1) {
-                            grid[ty][tx] = grid[next.y][next.x] + 1;
+                        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;
                         }
+
                     }
                 } else if (abs(i) == 2) {
@@ -68,16 +87,17 @@
 
                     for (int j = -1; j <= 1; j += 2) {
-                        if (next.y + j < 0 || next.y + j > r -  1) continue;
-
-                        int tx = next.x + i;
-                        int ty = next.y + j;
-                        if (grid[ty][tx] > grid[next.y][next.x] + 1) {
-                            grid[ty][tx] = grid[next.y][next.x] + 1;
+                        if (current.y + j < 0 || current.y + j > r -  1) continue;
 
+                        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;
                         }
                     }
                 }else {
-                    cerr << "dafuq?" << endl;
+                    //cerr << "dafuq?" << endl;
                 }
             }
@@ -86,5 +106,7 @@
         }
 
-        if (grid[lr][lc] == numeric_limits<int>::max()) {
+        //  cout << "&&&&&&&&&&" << endl;
+
+        if (grid[lr][lc] == INF) {
             cout << "impossible" << endl;