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.
分析:为了保证时间最优,每个人到达终点的时间是相同的,因此他们乘车时间也相同。对于乘有k个人的车,需要载n/k(上取整)次。为了保证尽可能让车载人,最后一组一定是乘车直接到达终点的。车运行的过程中会有n/k(上取整)-1次来回和最后一次去程。车运行的总时间和第一批人到达的时间相同,通过等式得出车载人的路程进而求出结果。
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
double l,v1,v2;
cin>>n>>l>>v1>>v2>>k;
int r = n / k + (n % k == 0 ?0:1);
double x = (v1 + v2) * l / (2 * v1 * r - v1 + v2);
printf("%.10f\n",(l - x) / v1 + x / v2);
return 0;
}