D. As Fast As Possible
On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v1. To get to the excursion quickly, it was decided to rent a bus, which has seats for k people (it means that it can't fit more than k people at the same time) and the speed equal to v2. In order to avoid seasick, each of the pupils want to get into the bus no more than once.
Determine the minimum time required for all n pupils to reach the place of excursion. Consider that the embarkation and disembarkation of passengers, as well as the reversal of the bus, take place immediately and this time can be neglected.
The first line of the input contains five positive integers n, l, v1, v2 and k (1 ≤ n ≤ 10 000, 1 ≤ l ≤ 109,1 ≤ v1 < v2 ≤ 109, 1 ≤ k ≤ n) — the number of pupils, the distance from meeting to the place of excursion, the speed of each pupil, the speed of bus and the number of seats in the bus.
Print the real number — the minimum time in which all pupils can reach the place of excursion. Your answer will be considered correct if its absolute or relative error won't exceed 10 - 6.
5 10 1 2 5
5.0000000000
3 6 1 2 1
4.7142857143
In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.
为了使时间最短,肯定是同时出发,同时到达。然后,然后就不会做了。QAQ
看了这位菊苣的解释,清晰了。链接:http://blog.csdn.net/acm_fighting/article/details/52003538
思路:要使最快的话,那么每个人达到终点的时间应该都是相同的,所以每个人乘车的路程也是相同的
设times=n/k+(n%k == 0 ? 0:1),a为每个人乘车的路程
除了最后一次载客之外,另外每次载客都还需要回来载下一批,t为来回的时间,x为下一次载的人当前的位置
那么x+t*v1表示经过t时间后下一次载的人的位置,(t-a/v2)*v2表示汽车走了a之后返回走的路程
所以x+t*v1=a+x-(t-a/v2)*v2,(画图一下就看出)
那么t=2*a/(v1+v2)
而且人到终点的总时间和车到终点的总时间是相同的,即t*(times-1)+a/v2=a/v2+(l-a)/v1
解出a=(v1+v2)*l/(v1+v2+2*(times-1)*v1)。
答案为a/v2+(l-a)/v1.
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <map> 6 using namespace std; 7 typedef long long ll; 8 int main() 9 { 10 double l,v1,v2,times,t,a; 11 int n,k; 12 cin>>n>>l>>v1>>v2>>k; 13 times = n/k+(n%k==0?0:1); 14 a = (v1+v2)*l/(v1+v2+2*(times-1)*v1); 15 t = (l-a)/v1+a/v2; 16 printf("%lf ",t); 17 return 0; 18 }