Codeforces Round #364 (Div. 2) D 数学推导



链接:戳这里


D. As Fast As Possible
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.


题意:

n个人打算去玩,路程长度为L,他们租了船,船最多装载k个人,每人因为晕船所以只乘坐一次,步行速度为v1。

坐船速度为v2。问怎样安排使得所有人到达目的地的时间最短。


思路:

n个人肯定是一起到达目的地时间最短,那么每个人全程坐车的时间和走路的时间肯定是相同的

假设第一批人先上船(共n/k批人,向下取整),乘坐了L1的路程。此时花费的时间T1=L1/v2

现在第一批人走路去终点,船沿路返回去接第二批人。

与第二批人相遇,花费时间为T2,第二批人走的路程也就为(T1+T2)*v1

还有一个关系式满足:当前第二批人走的总路程+船返回的路程=L1

(T1+T2)*v1+T2*v2=L1  => T2=(L1-L1*v1/v2)/(v1+v2)

知道T1,T2之后可以推出船返回与第二批人相遇的地点为d=(T1+T2)*v1=(2*L1*v1)/(v1+v2)

现在船在d的位置接第二批人经过T1秒之后到达一个点d2在返回去接第三批人。

如此往复!每次接人都走了距离d,最后一次接人肯定是在L-L1处接然后开船L1距离到达终点

所以有(cnt-1)*d=L-L1 表示最后一次接人的位置+L1直接到达终点

推出L1=L*(v1+v2)/((2*cnt-1)*v1+v2);

总时间T=L1/v2+(L-L1)/v1;


代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n,k;
long double v1,v2,L;
int main(){
    cin>>n>>L>>v1>>v2>>k;
    int cnt=0;
    if(n%k==0) cnt=n/k;
    else cnt=n/k+1;
    long double l1=L*(v1+v2)/((2*cnt-1)*v1+v2);
    long double ans=l1/v2+(L-l1)/v1;
    cout<<setprecision(20)<<ans<<endl;
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值