Source code for submission s1152

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.  
  51. for (int i=0; i<103; i++)
  52. for (int j=0; j<103; j++)
  53. grid[i][j]=-1;
  54.  
  55. pair<int,int> leaf = make_pair(lr,ls);
  56.  
  57. todo.push(make_pair(gr,gs));
  58. grid[gr][gs]=0;
  59.  
  60. while(!todo.empty()){
  61.  
  62. pair<int,int> current = todo.front();
  63. todo.pop();
  64.  
  65. /*for (int i=1; i<=r; i++)
  66.   {
  67.   for (int j=1; j<=s; j++)
  68.   cout << " " << grid[i][j];
  69.   cout << endl;
  70.   }*/
  71.  
  72. for(vector< pair<int,int> >::iterator i = moves.begin(); i!=moves.end();i++)
  73. {
  74. pair<int,int> next = make_pair(current.first+i->first,current.second+i->second);
  75.  
  76. if(next.first >= 1 && next.first <= r && next.second >= 1 && next.second <= s){
  77. if(grid[next.first][next.second]==-1) {
  78. grid[next.first][next.second]=grid[current.first][current.second]+1;
  79. todo.push(next);
  80. }
  81. }
  82. }
  83. //cout << endl << "/////////////////////////////" << endl;
  84. }
  85.  
  86. if(grid[leaf.first][leaf.second]==-1) cout << "impossible" << endl;
  87. else {
  88. cout << grid[leaf.first][leaf.second] << endl;
  89. }
  90. //1==1;
  91. }
  92.  
  93.  
  94. }
  95.  
  96. #elif PROJECT == 5
  97.  
  98. int main()
  99. {
  100. int n,m;
  101.  
  102. while (cin >> n >> m)
  103. {
  104. // we are screwed
  105. for (int i=0; i<m; i++)
  106. {
  107. }
  108. }
  109. }
  110.  
  111. #elif PROJECT == 6
  112.  
  113. int main() {
  114.  
  115. unsigned long long m, p, l, e ,r, s, n;
  116.  
  117. while (cin >> m >> p >> l >> e >> r >> s >> n) {
  118. for (int i = 0; i < n; i++) {
  119. int m1, p1, l1;
  120. m1 = p / s;
  121. p1 = l / r;
  122. l1 = m * e;
  123.  
  124. m = m1; p = p1; l = l1;
  125. }
  126. cout << m << endl;
  127. }
  128.  
  129. return 0;
  130. }
  131.  
  132. #endif
  133.  

Diff to submission s1055

main.cpp

--- c4.s1055.cteam098.grasshop.cpp.0.main.cpp
+++ c4.s1152.cteam098.grasshop.cpp.0.main.cpp
@@ -62,4 +63,11 @@
             todo.pop();
 
+            /*for (int i=1; i<=r; i++)
+            {
+                for (int j=1; j<=s; j++)
+                    cout << "  " << grid[i][j];
+                cout << endl;
+            }*/
+
             for(vector< pair<int,int> >::iterator i = moves.begin(); i!=moves.end();i++)
             {
@@ -69,14 +77,15 @@
                     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);
                     }
                 }
             }
+            //cout << endl << "/////////////////////////////" << endl;
             }
 
         if(grid[leaf.first][leaf.second]==-1) cout << "impossible" << endl;
+        else {
+            cout << grid[leaf.first][leaf.second] << endl;
+        }
         //1==1;
     }
@@ -87,4 +96,17 @@
 #elif PROJECT == 5
 
+int main()
+{
+    int n,m;
+
+    while (cin >> n >> m)
+    {
+    // we are screwed
+        for (int i=0; i<m; i++)
+        {
+        }
+    }
+}
+
 #elif PROJECT == 6
 
@@ -94,6 +116,6 @@
 
     while (cin >> m >> p >> l >> e >> r >> s >> n) {
-        for (ull i = 0; i < n; i++) {
-            ull m1, p1, l1;
+        for (int i = 0; i < n; i++) {
+            int m1, p1, l1;
             m1 = p / s;
             p1 = l / r;