HDU 6581 Vacation

Topic links: http://acm.hdu.edu.cn/showproblem.php?pid=6581


Ideas: 1 final by stopping the line, it must be behind a car Duzhe remaining all the cars, then the impact of time on only the front car. Due to the speed of the car is always the same, so we can calculate the answer:

     From start to finish the car to go in total (initial distance from the stop line S I  length interposed between 0 and vehicle + vehicle  [Sigma L I ) / V I .

   2. So for every car, it is assumed to be 0 and the vehicle plugging together the most forward of a car, you can calculate a value, maximum value calculated is the answer to all of the vehicles. The greedy hard to think of, my understanding is the longest car would block the back of the car, in the longest car in front of the car than it fast so it does not get stuck.

AC Code:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 1e5 +5;
 4 struct edge{
 5     double v,s,len;
 6 }es[maxn];
 7 int main()
 8 {
 9     int n;
10     while(~scanf("%d",&n))
11     {
12         int m = 1;
13         for(int i = 1;i <= n + 1;i++) scanf("%lf",&es[i].len);
14         for(int i = 1;i <= n + 1;i++) scanf("%lf",&es[i].s);
15         for(int i = 1;i <= n + 1;i++) scanf("%lf",&es[i].v);
16         double ans = 0;
17         double lazy = 0;
18         for(int i = 1;i <= n + 1;i++)
19         {
20             if(i != 1) lazy += es[i].len;
21             double t = (es[i].s + lazy) / es[i].v;
22             ans = max(t,ans);
23         }
24         printf("%.10f\n",ans);
25     }
26     return 0;
27 }

 

Guess you like

Origin www.cnblogs.com/Carered/p/11228330.html