Codeforces700A As Fast As Possible 数学推理

来源:互联网 发布:c语言竖线 编辑:程序博客网 时间:2024/05/16 07:51

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.

Input

The first line of the input contains five positive integers nlv1v2 and k (1 ≤ n ≤ 10 0001 ≤ l ≤ 109,1 ≤ v1 < v2 ≤ 1091 ≤ 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.

Output

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.

Examples
input
5 10 1 2 5
output
5.0000000000
input
3 6 1 2 1
output
4.7142857143
Note

In the first sample we should immediately put all five pupils to the bus. The speed of the bus equals 2and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.

题意就是求一群小学生都到达目的地的最短时间,有 bus 这一种交通工具,但每个小学生只能坐一次 bus 。因此,每个小学生到达目的地的时间,就是坐 bus 的时间+走路的时间,最短时间显然取决于坐 bus 路程最短的那人。那么,最优的情况应该就是,所有人坐 bus 的路程都一样,这样就能够保证最快的和最慢的所花的时间相同。
然后,我们先考虑简单的情况,由于 bus 来回趟数是和 n/k 有关的,那么先分析 n/k 为 2 的情况,该情况下, bus 先送一半人,再回来接另一半人。我们可以假设 bus 载人走过路径为 K*l ,那么 走路的路径为 (1-K)*l ,那么,由 bus 需要回去接另一波小学生,我们可以计算得到:
 ( K + K - (1 - K ) ) * l / v2 = ( 1-K ) * l / v1
那么,总时间就是:                                                                 K * l / V2 + ( 1 - K ) * l / v1
这样我们已经解决了 n/k 为 2 的情况,接下来考虑 n/k 为 3 的情况,观察 bus 回去接第二波小学生的那个时刻以后,你会发现这是和 n/k 为 2 的情况是一样的,当我们仍用 K*l 去表示 bus 载人走过路径,那么此时每波小学生走路的路径为 2 * ( 1 - K ) * l ,注意此时长度之和不是直接等于原值l,但是通过比例放缩,能够得到实际值。
这时候,应该可以想到适用所有的公式了,bus 载人走过路径为 K*l ,那么 走路的路径为 (n/k-1)*(1-K)*l,而 K 又可以通过 上已给的式子计算出来,最后的结果是:
l * [ k/v2 + ( n / k -1 )*( 1 - k ) / v1] / ( k + ( n / k - 1 ) * ( 1 - k ) ) 

#include <cstdio>#include <map>#include <set>#include <vector>#include <queue>#include <stack>#include <cmath>#include <algorithm>#include <cstring>#include <string>using namespace std;#define INF 0x3f3f3f3ftypedef long long LL;int main(){    int n,l,v1,v2,k;    while(~scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k)){        if(k>=n){            printf("%.10lf\n",l*1.0/v2);            continue;        }        int t=(n-1)/k;        double s=v2*1.0/v1;        double kk=(1+s)/(3+s);        double temp=kk+t*(1-kk);        temp=l*1.0/(temp*v1);        printf("%.10lf\n",temp*(kk/s+t*(1-kk)));    }    return 0;}


1 0
原创粉丝点击