一开始推以为要推出一个一元二次方程,然后二分解。后来越来越推不出,只好搜题解看看。
以下内容皆为转载,转自xgogoforit的博客
题意
开始的时候还没弄懂题意,以为就是一个追击问题的极限形式,但是样例都对不上。还有就是这句话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 <cstdio>
int n,k,r;
double l, v1, v2;
int main()
{
scanf("%d%lf%lf%lf%d", &n, &l, &v1, &v2, &k);
r = n / k + ((n%k) ? 1 : 0);
double g = (l*(v1 + v2)) / (2 * v1*((r - 1)*1.0) + v1 + v2);
double ans = (l - g) / v1 + g / v2;
printf("%.10lf\n", ans);
return 0;
}
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.
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.
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.
5 10 1 2 5
5.0000000000
3 6 1 2 1
4.7142857143
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.