Codeforces 701D. As Fast As Possible(二分)

来源:互联网 发布:一辈子单身感受知乎 编辑:程序博客网 时间:2024/06/06 01:24
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 lengthl meters. Each of the pupils will go with the speed equal tov1. To get to the excursion quickly, it was decided to rent a bus, which has seats fork people (it means that it can't fit more thank people at the same time) and the speed equal tov2. In order to avoid seasick, each of the pupils want to get into the busno 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 andk (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 exceed10 - 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 equals2 and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.

题意:现在有n个人,路程长度为l,人行走速度为v1,有一辆车,每次能载k人,车行走速度为v2,每个人最多只能坐一次车,求n个人走完l的最少花费时间。

思路:每个人只能坐一次车,所以最后到达终点的人决定总时间,可以看出,用车每次载k个人,行走一定的距离,然后折返载下一趟人追上上一趟的人这种情

况能得出最优值。所以假设第一趟车载人时间为t1,所以两边的人相距v2*t1-v1*t1,假设第二趟车载人时间为t2,因为要追上上一趟,所以v2*t1-v1*t1+v1*t2=v2*t2,

所以t1=t2,也就是每人坐车的时间相等。

车载人的趟数:p=(n+k-1)/k。

设总时间为t,每人坐车的时间t1,则v1*(t-t1)+v2*t1=l,所以t1可以用t表示,设折返时间为t2,则(v2-v1)*t1=(v2+v1)*t2,而且t2*(p-1)+t1*p<=t。这样二分时间t就

可以求出结果。

#include <bits/stdc++.h>using namespace std;double v1, v2, l;int n, k;bool check(double t){    double t2 = (l-t*v1)/(v2-v1);    double t3 = (v2-v1)*t2/(v2+v1);    int p = (n+k-1)/k;    return t2*p+(p-1)*t3<=t;}int main(){    scanf("%d %lf %lf %lf %d", &n, &l, &v1, &v2, &k);    double ll = l/v2, r = l/v1, mid;    for(int i = 1;i <= 100000;i++){        mid = (ll+r)/2;        if(check(mid)) r = mid;        else ll = mid;    }    printf("%.7lf\n", r);}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 药流12天还流血怎么办? 把别人车刮了怎么办 车划掉漆了怎么办啊 倒车时碰了车怎么办 车头掉了一点漆怎么办 新买的车被刮了怎么办 白色车车头漆掉了一小块怎么办 临时牌照丢了1张怎么办 临牌遗失了一张怎么办 临牌只有一张了怎么办 临时牌丢了一个怎么办 药流出血特别多怎么办 新车刮擦了一点怎么办 自己的车撞墙了怎么办 新车被撞了个坑怎么办 车门被刮变形了怎么办 撞到别人的新车怎么办 新车掉了一点漆怎么办 新车擦了点漆怎么办 车挂了一点漆怎么办 第一天上班中途想走了怎么办 车子前脸裂开了怎么办 不想干了想辞职怎么办 药流期间老是吐怎么办 在工厂上班辞工后没发工资怎么办 培训期三天想走怎么办 药流吃了药吐了怎么办 工作3天不下去怎么办 在新公司融不进去怎么办 药流吃药吐了怎么办 药流期间发烧了怎么办 药流时第一天出现呕吐怎么办有事吗 药流第一天忘记第二次吃药了怎么办 药流吃药后吐了怎么办 药流只排血块不见孕囊怎么办 药流三天还有血怎么办 药流15天同房了怎么办 药流22天同房了怎么办 药流一直不排出怎么办 宝宝脸过敏红了怎么办 小孩湿疹脸上都是红红的怎么办