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.、
题意:n个学生 走长度为l的行程 步行速度为v1 公车的速度v2 车上有k个位置 求最少的时间使得所有的学生到达终点;
题解:考虑什么是最优的情况呢?应该使得汽车最少的时间空车行驶,使得所有的学生坐车时间和步行时间应该相同
并且同时到达终点
上图为最优情况下 汽车的运动轨迹 保证所有的学生同时到达终点
每一个子运动的distance=v2*t-(v2-v1)/(v2+v1)*t*v2;
(t为运送第一批学生停车的时刻,返程为汽车与其余学生的相向运动)
可以发现l=p*v2*t-(v2-v1)/(v2+v1)*t*v2*(p-1); (p为学生的批数)
从而推导出t=l/(p*v2-(v2-v1)/(v2+v1)*v2*(p-1))
因为所有的学生同时到达 所以选择第一批学生计算总时间(l-v2*t)/v1+t (步行时间+坐车时间)
@dream-boy
//code by drizzle #include<bits/stdc++.h> #include<iostream> #include<cstring> #include<cstdio> #define ll __int64 #define PI acos(-1.0) #define mod 1000000007 using namespace std; int n,k; double l,v1,v2; int p; int main() { scanf("%d %lf %lf %lf %d",&n,&l,&v1,&v2,&k); double L=0; p=n/k; if((n%k)>0) p++; L=l/(p*v2-(v2-v1)/(v2+v1)*v2*(p-1)); printf("%.7f ",(l-v2*L)/v1+L); return 0; }