Cf 364div2 D[数学公式推导]

来源:互联网 发布:linux获取线程优先级 编辑:程序博客网 时间:2024/06/05 04:58

题目连接

http://codeforces.com/contest/701/problem/D

Description

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.

Sample Input

3 6 1 2 1

Sample Output

4.7142857143

题意

开始的时候还没弄懂题意,以为就是一个追击问题的极限形式,但是样例都对不上。还有就是这句话as well as the reversal of the bus,我以为是返回的时候也是不要时间的意思,但是好像应该是车掉头不要时间 -。- …
题意就是一群学生要到一个目的地去,他们当中没人可以有一次坐车的机会,问怎么才能使用的总时间最少。

题解

所用的总时间最少应该是大家都同时到达,没有人在终点等待其他人,也就没有时间浪费掉。在大家都同时到达的情况下,那么每人乘车的时间和步行的时间应该是相同的。要注意的double运算的时候,要保证每一个部分都是double,某些时候要强制转换。

推导

设某人1处在x的位置,某人2乘车的距离为a,车送完某人2返回去接某人1的时间为t。
一个要接g=n/k[分偶数奇数讨论+1or not +1]组人
x+t*v1=x+a-(t-a/v2)化简得 t= (2 *a)/(v1+v2)
最后一个人在车上与其他所有人同时到达终点,那么车行驶的时间与一个人所用的总时间是相同的则
a/v2 + t*(g-1)=a/v2 +(l-a)/v1 化简得 a=(v1+v2) *l/(2 *g *v1+v2-v1)
t=a/v2+(l-a)/v1

代码

#include<bits/stdc++.h>using namespace std;int main(){    int n,l,v1,v2,k;    scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k);    int g;    if(n%k==0){g=n/k;}    else g=(n/k)+1;    double a=((double)(v1+v2)*l)/(2*g*v1+v2-v1);    double t=a/v2+(l-a)/v1;    printf("%.10lf",t);}
0 0
原创粉丝点击