Codeforces Round #364 (Div. 2) D. As Fast As Possible

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


题意:给你n个人,每个人走路的速度v1,有一辆车速度为v2,每次可以载k个人,总路程为l,每个人只能上一次车,问最少需要多少时间把所有人送到终点

思路:要使最快的话,那么每个人达到终点的时间应该都是相同的,所以每个人乘车的路程也是相同的

设g=n/k+(n%k == 0 ? 0:1),a为每个人乘车的路程

除了最后一次载客之外,另外每次载客都还需要回来载下一批,t为来回的时间,x为下一次载的人当前的位置

那么x+t*v1表示经过t时间后下一次载的人的位置,(t-a/v2)*v2表示汽车走了a之后返回走的路程

所以x+t*v1=a+x-(t-a/v2)*v2,

那么t=2*a/(v1+v2)

而且人到终点的总时间和车到终点的总时间是相同的,即t*(g-1)+a/v2=a/v2+(l-a)/v1

解出a=(v1+v2)*l/(v1+v2+2*(g-1)*v1)

答案为a/v2+(l-a)/v1

#include<bits/stdc++.h>
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);
    printf("%.7f\n",a/v2+(l-a)/v1);
    return 0;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值