当前位置:   article > 正文

Codeforces700A As Fast As Possible 数学推理_codeforces 700a

codeforces 700a

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 ) ) 

  1. #include <cstdio>
  2. #include <map>
  3. #include <set>
  4. #include <vector>
  5. #include <queue>
  6. #include <stack>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <cstring>
  10. #include <string>
  11. using namespace std;
  12. #define INF 0x3f3f3f3f
  13. typedef long long LL;
  14. int main()
  15. {
  16. int n,l,v1,v2,k;
  17. while(~scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k)){
  18. if(k>=n){
  19. printf("%.10lf\n",l*1.0/v2);
  20. continue;
  21. }
  22. int t=(n-1)/k;
  23. double s=v2*1.0/v1;
  24. double kk=(1+s)/(3+s);
  25. double temp=kk+t*(1-kk);
  26. temp=l*1.0/(temp*v1);
  27. printf("%.10lf\n",temp*(kk/s+t*(1-kk)));
  28. }
  29. return 0;
  30. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/71343
推荐阅读
相关标签
  

闽ICP备14008679号