Codeforces 701D

本文介绍了一种算法,用于计算一组学生使用步行和巴士结合的方式达到目的地所需的最短时间。考虑到巴士的容量限制及学生的步行速度,算法通过精确计算巴士行驶距离来确保整体效率。

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

D. As Fast As Possible
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ≤ 1091 ≤ 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
Copy
5 10 1 2 5
output
Copy
5.0000000000
input
Copy
3 6 1 2 1
output
Copy
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.

分析:为了保证时间最优,每个人到达终点的时间是相同的,因此他们乘车时间也相同。对于乘有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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值