Advertisement
bogolyubskiyalexey

Untitled

Mar 21st, 2021
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct TPosition {
  5.     TPosition(int index, double dist, double totalDist)
  6.         : Index(index)
  7.         , Dist(dist)
  8.         , TotalDist(totalDist)
  9.     {}
  10.     int Index;
  11.     double Dist;
  12.     double TotalDist;
  13. };
  14.  
  15. bool IsTwoLaneRoad(int index) {
  16.     return index % 2 == 0;
  17. }
  18.  
  19. int main() {
  20.     int T, R, K;
  21.     std::cin >> T >> R >> K;
  22.     std::vector<int> h(K);
  23.    
  24.     int L = 0;
  25.     for (auto& hh : h) {
  26.         std::cin >> hh;
  27.         L += hh;
  28.     }
  29.     TPosition A(0, 0, 0);
  30.     TPosition B(K - 1, h.back(), L);
  31.     double time = 0;
  32.     int answer = 0;
  33.     while(true) {
  34.         double between = B.TotalDist - A.TotalDist;
  35.         if (between <= R) {
  36.             if (A.Index == B.Index) {
  37.                 if (IsTwoLaneRoad(A.Index)) {
  38.  
  39.                 } else {
  40.                     ???
  41.                 }
  42.             } else {
  43.                
  44.             }
  45.         } else {
  46.             double timeToRide = (between - R) / 2;
  47.             timeToRide = std::min(timeToRide, h[A.Index] - A.Dist);
  48.             timeToRide = std::min(timeToRide, B.Dist);
  49.             if (A.Dist >= h[A.Index]) {
  50.                 A.Dist = 0;
  51.                 ++A.Index;
  52.             }
  53.             if (B.Dist <= 0) {
  54.                 --B.Index;
  55.                 B.Dist = h[B.Index];
  56.             }
  57.             A.Dist += timeToRide;
  58.             A.TotalDist += timeToRide;
  59.             B.Dist -= timeToRide;
  60.             B.TotalDist -= timeToRide;
  61.             time += timeToRide;
  62.         }
  63.         if (time > T) { // T included ????
  64.             break;
  65.         }
  66.         if (A.Index == K) {
  67.             std::cout << "At " << time << " A->B finished." << std::endl;
  68.             ++answer;
  69.             A = TPosition(0, 0, 0);
  70.         }
  71.         if (B.Index == -1) {
  72.             std::cout << "At " << time << " B->A finished." << std::endl;
  73.             ++answer;
  74.             B = TPosition(K - 1, h.back(), L);
  75.         }
  76.     }
  77.  
  78.  
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement