cf700A As Fast As Possible

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

 

这题特么坑爹

n个人位于数轴上0位置要走到L去,有一辆车也从0出发,只能载k个人,而且每个人都只能上车1次。人的速度都是v1,车的速度是v2,问这n个人都到达L的最小时间。

一看这输出,这小数,马上想到二分了,不然你想要怎么做(一场cf连着两题二分这很不自然)

判定我想了很久。。关键是车子可以运到一半把人赶下去叫他们自己走,然后回去载人

后来想想,如果规定了答案是ans,只要把人放在一个地方,使得你自己走过去到L的时间刚好是ans就可以了

那车子每一波载人的落点都可以算出来了

然后这题目tm还卡精度!!!我判定时再二分每次车子的落点,结果n=1w的时候精度爆了,然后wa。。

后来场外咨询(雾)换了一个判定方法(可以,这很数学)

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<deque>
 9 #include<set>
10 #include<map>
11 #include<ctime>
12 #define LL long long
13 #define inf 0x7ffffff
14 #define pa pair<int,int>
15 using namespace std;
16 inline LL read()
17 {
18     LL x=0,f=1;char ch=getchar();
19     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
20     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
21     return x*f;
22 }
23 inline void write(LL a)
24 {
25     if (a<0){printf("-");a=-a;}
26     if (a>=10)write(a/10);
27     putchar(a%10+'0');
28 }
29 inline void writeln(LL a){write(a);printf("\n");}
30 int n,K;
31 double l,v1,v2;
32 double now;
33 bool check(double ans)
34 {
35     double y=(l-ans*v1)/(v2-v1);
36     double s=v1*y+(v2-v1)*y/(v1+v2)*v1;
37     return (n-1)/K*s+v2*y<=l;
38 }
39 int main()
40 {
41     n=read();l=read();v1=read();v2=read();K=read();
42     if(v2<v1)v2=v1;
43     double L=l/v2,R=l/v1;
44     for(int i=1;i<=60;i++)
45     {
46         double mid=(L+R)/2;
47         if(check(mid))R=mid;
48         else L=mid;
49     }
50     printf("%.12lf",L);
51     return 0;
52 }
cf700A

 

转载于:https://www.cnblogs.com/zhber/p/5698471.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值