Luo Gu P1258 car problem

Topic Portal

Problem-solving ideas:

First of all, everyone do a car, and two people to arrive at the same time, in order to make the shortest total time.

So, we set the starting point is A, endpoint B, with A to the car to open the C point A to point B came off, and at the same time turn the car has come to the point D faces the line B, meet at point E, the final B to B with the car away, and A simultaneously reach.

Then we half point C, until the error is less than a certain value.

AC Code:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 
 5 using namespace std;
 6 
 7 double s,b,a,be,end,p,t1,t2,s1,s2,ta,tb;
 8 
 9 int main() {
10     cin >> s >> a >> b;
11     be = 0;
12     end = s;
13     do {
14         p = (be + end) / 2.0;
15         ta = p / b;
16         tb = (p - a * ta) / (a + b);
17         t1 = ta + (s - p) / a;
18         t2 = tb + ta + (s - (ta + tb) * a) / b;
19         if(t1 < t2)
20             end = p;
21         else 
22             be = p;
23     }
24     while(fabs(t1 - t2) > 1e-8);
25     printf("%0.6lf",t1);
26     return 0;
27 }

 

Guess you like

Origin www.cnblogs.com/lipeiyi520/p/11267652.html