Source code for submission s1092

Go to diff to previous submission

ants.cpp

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <climits>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.  
  9. int length, ants, minR=INT_MAX, maxL=INT_MIN, pos, timeR, size=100000, lenR=0, lenL=0, medL, medR;
  10. char dir;
  11. int left[size];
  12. int right[size];
  13. bool wasRight=false, wasLeft=false;
  14.  
  15. while(cin>> length >> ants)
  16. {
  17. for(int i=0; i<ants; i++)
  18. {
  19. cin >> pos >> dir;
  20. if(dir=='R')
  21. {
  22. wasRight=true;
  23. if(pos<minR) minR=pos;
  24. right[lenR]=pos;
  25. lenR++;
  26. }
  27. else
  28. {
  29. wasLeft=true;
  30. if(pos>maxL) maxL=pos;
  31. left[lenL]=pos;
  32. lenL++;
  33. }
  34. }
  35. timeR=length-minR; //cas
  36.  
  37. if(wasLeft && !wasRight)
  38. {
  39. cout << "The last ant will fall down in " << maxL << " seconds - started at " << maxL << "." << endl;
  40. }
  41. else if(!wasLeft && wasRight)
  42. {
  43. cout << "The last ant will fall down in " << timeR << " seconds - started at " << minR << "." << endl;
  44. }
  45. else
  46. {
  47. if(timeR<maxL)
  48. {
  49. //cout << maxL << " " << minR << endl;
  50. sort(&left[0], &left[lenL]);
  51. if(lenL==0)
  52. medL=0;
  53. else if(!(lenL%2))
  54. medL=(lenL/2)-1;
  55. else
  56. medL=lenL/2;
  57.  
  58. cout << "The last ant will fall down in " << maxL << " seconds - started at " << left[medL] << "." << endl;
  59.  
  60. }
  61. else if(timeR>maxL)
  62. {
  63. //cout << maxL << " " << minR << endl;
  64. sort(&right[0], &right[lenR]);
  65. if(lenR==0)
  66. medR=0;
  67. else if(!(lenR%2))
  68. medR=lenR/2;
  69. else
  70. medR=lenR/2;
  71. cout << "The last ant will fall down in " << minR << " seconds - started at " << right[medR] << "." << endl;
  72. }
  73. else if(timeR==maxL)
  74. {
  75. //cout << maxL << " " << timeR << endl;
  76. sort(&left[0], &left[lenL]);
  77. sort(&right[0], &right[lenR]);
  78.  
  79. if(lenL==0)
  80. medL=0;
  81. else if(!(lenL%2))
  82. medL=(lenL/2)-1;
  83. else
  84. medL=lenL/2;
  85.  
  86.  
  87. if(lenR==0)
  88. medR=0;
  89. else if(!(lenR%2))
  90. medR=lenR/2;
  91. else
  92. medR=lenR/2;
  93.  
  94. cout << "The last ant will fall down in " << maxL << " seconds - started at " << left[medL] << " and " << right[medR] << "." << endl;
  95. }
  96. }
  97. lenL = lenR = 0;
  98. minR=INT_MAX; maxL=INT_MIN;
  99. wasLeft = wasRight = false;
  100.  
  101. }
  102.  
  103.  
  104. return 0;
  105. }
  106.  

Diff to submission s1073

ants.cpp

--- c4.s1073.cteam042.ants.cpp.0.ants.cpp
+++ c4.s1092.cteam042.ants.cpp.0.ants.cpp
@@ -52,5 +52,5 @@
                                         medL=0;
                                 else if(!(lenL%2)) 
-                                        medL=((lenL-1)/2 + (lenL-1)/2 + 1)/2;
+                                        medL=(lenL/2)-1;
                                 else
                                         medL=lenL/2;
@@ -80,5 +80,5 @@
                                         medL=0;
                                 else if(!(lenL%2)) 
-                                        medL=((lenL-1)/2 + (lenL-1)/2 + 1)/2;
+                                        medL=(lenL/2)-1;
                                 else
                                         medL=lenL/2;