Codeforces700A As Fast As Possible 数学推理

探讨一群小学生利用步行及有限座位的巴士达到目的地的最短时间问题,通过数学建模得出最优解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 0x3f3f3f3f
typedef 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
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值