codeforces#364DAs 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 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.
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 2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.

要使最快的话,那么每个人达到终点的时间应该都是相同的,所以每个人乘车的路程也是相同的
设g=n/k+(n%k == 0 ? 0:1),a为每个人乘车的路程
除了最后一次载客之外,另外每次载客都还需要回来载下一批

这里写图片描述

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#define db double

using namespace std;

int main(){
    int n,k;
    double l,v1,v2;
    scanf("%d %lf %lf %lf %d",&n,&l,&v1,&v2,&k);
    int g=n/k;
    if(n%k!=0) g++;

    double a=(v1+v2)*l/(v1+v2+2*(g-1)*v1);
    double out=a/v2+(l-a)/v1;
    printf("%.7f\n",out);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值