Source code for submission s922

Go to diff to previous submission

ants.cpp

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <climits>
  6.  
  7. #include <iostream>
  8. #include <algorithm>
  9.  
  10. #include <vector>
  11. #include <string>
  12. #include <map>
  13. #include <queue>
  14. #include <deque>
  15. #include <stack>
  16. #include <set>
  17.  
  18. //~ using namespace std;
  19.  
  20. typedef long double num;
  21. typedef long long int lint;
  22. typedef struct { int x, y; } intpoint;
  23. typedef struct { num x, y; } numpoint;
  24. typedef struct { lint x, y; } lintpoint;
  25.  
  26. #define EPS (1e-7L)
  27. #define PI (4.0L * atanl(1.0L))
  28.  
  29. #define min(a, b) ((a) < (b) ? (a) : (b))
  30. #define max(a, b) ((a) > (b) ? (a) : (b))
  31. #define abs(a) ((a) < 0 ? -(a) : (a))
  32.  
  33. int main(int argc, char *argv[]) {
  34. while (true) {
  35. int ants, len;
  36.  
  37. bool existL = false, existR = false, collision;
  38.  
  39. if (2 != scanf("%u %u\n", &len, &ants))
  40. break;
  41. int maxL = 0, minR = len, mindist = len;
  42. std::vector<int> antssssss;
  43.  
  44.  
  45.  
  46. for (int ant = 0; ant < ants; ant++) {
  47. int start;
  48. char dir;
  49.  
  50. scanf("%u %c\n", &start, &dir);
  51.  
  52. if (dir == 'L') {
  53. existL = true;
  54. maxL = max(maxL, start);
  55. } else if (dir == 'R') {
  56. existR = true;
  57. minR = min(minR, start);
  58. }
  59. int aux = len%2 ? min(abs(len/2 - start), abs(len/2 + 1 - start)) : abs((len >>1) - start);
  60. if (aux < mindist)
  61. {
  62. antssssss.clear();
  63. antssssss.push_back(start);
  64. mindist = aux;
  65. }
  66. else
  67. if(aux == mindist)
  68. antssssss.push_back(start);
  69. }
  70.  
  71.  
  72.  
  73. int L = maxL, R = len - minR;
  74. if (existL && existR) {
  75. if (minR < maxL) {
  76. if(antssssss.size() == 2)
  77. printf("The last ant will fall down in %d seconds - started at %d and %d.\n", max(L, R), antssssss[0], antssssss[1]);
  78. else
  79. printf("The last ant will fall down in %d seconds - started at %d.\n", max(L, R), antssssss[0]);
  80. }
  81. } else if (existR) {
  82. printf("The last ant will fall down in %d seconds - started at %d.\n", R, minR);
  83. } else if (existL) {
  84. printf("The last ant will fall down in %d seconds - started at %d.\n", L, maxL);
  85. } else {
  86. // not gonna happen
  87. }
  88. }
  89.  
  90. return 0;
  91. }
  92.  

Diff to submission s901

ants.cpp

--- c4.s901.cteam101.ants.cpp.0.ants.cpp
+++ c4.s922.cteam101.ants.cpp.0.ants.cpp
@@ -44,7 +44,4 @@
                 
                 
-                bool hasR = false, hasL = false;
-                int startR = INT_MAX, startL = 0;
-                
                 for (int ant = 0; ant < ants; ant++) {
                         int start;
@@ -53,16 +50,10 @@
                         scanf("%u %c\n", &start, &dir);
                         
-                        if (dir == 'L' && startL <= start) {
+                        if (dir == 'L') {
                                 existL = true;
                                 maxL = max(maxL, start);
-                                        
-                                hasL = true;
-                                startL = start;
-                        } else if (dir == 'R' && start <= startR) {
+                        } else if (dir == 'R') {
                                 existR = true;
                                 minR = min(minR, start);
-                                
-                                hasR = true;
-                                startR = start;
                         }
                         int aux = len%2 ? min(abs(len/2 - start), abs(len/2 + 1 - start)) : abs((len >>1) - start);
@@ -76,10 +67,9 @@
                                         if(aux == mindist)
                                                 antssssss.push_back(start);
-                                
                 }
                 
 
                 
-                int L = startL, R = len - startR;
+                int L = maxL, R = len - minR;
                 if (existL && existR) {
                         if (minR < maxL) {
@@ -90,7 +80,7 @@
                         }
                 } else if (existR) {
-                        printf("The last ant will fall down in %d seconds - started at %d.\n", R, startR);
+                        printf("The last ant will fall down in %d seconds - started at %d.\n", R, minR);
                 } else if (existL) {
-                        printf("The last ant will fall down in %d seconds - started at %d.\n", L, startL);
+                        printf("The last ant will fall down in %d seconds - started at %d.\n", L, maxL);
                 } else {
                         // not gonna happen