Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- struct TPosition {
- TPosition(int index, double dist, double totalDist)
- : Index(index)
- , Dist(dist)
- , TotalDist(totalDist)
- {}
- int Index;
- double Dist;
- double TotalDist;
- };
- bool IsTwoLaneRoad(int index) {
- return index % 2 == 0;
- }
- int main() {
- int T, R, K;
- std::cin >> T >> R >> K;
- std::vector<int> h(K);
- int L = 0;
- for (auto& hh : h) {
- std::cin >> hh;
- L += hh;
- }
- TPosition A(0, 0, 0);
- TPosition B(K - 1, h.back(), L);
- double time = 0;
- int answer = 0;
- while(true) {
- double between = B.TotalDist - A.TotalDist;
- if (between <= R) {
- if (A.Index == B.Index) {
- if (IsTwoLaneRoad(A.Index)) {
- } else {
- ???
- }
- } else {
- }
- } else {
- double timeToRide = (between - R) / 2;
- timeToRide = std::min(timeToRide, h[A.Index] - A.Dist);
- timeToRide = std::min(timeToRide, B.Dist);
- if (A.Dist >= h[A.Index]) {
- A.Dist = 0;
- ++A.Index;
- }
- if (B.Dist <= 0) {
- --B.Index;
- B.Dist = h[B.Index];
- }
- A.Dist += timeToRide;
- A.TotalDist += timeToRide;
- B.Dist -= timeToRide;
- B.TotalDist -= timeToRide;
- time += timeToRide;
- }
- if (time > T) { // T included ????
- break;
- }
- if (A.Index == K) {
- std::cout << "At " << time << " A->B finished." << std::endl;
- ++answer;
- A = TPosition(0, 0, 0);
- }
- if (B.Index == -1) {
- std::cout << "At " << time << " B->A finished." << std::endl;
- ++answer;
- B = TPosition(K - 1, h.back(), L);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement