赞
踩
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 2and the distance is equal to 10, so the pupils will reach the place of excursion in time 10 / 2 = 5.
题意就是求一群小学生都到达目的地的最短时间,有 bus 这一种交通工具,但每个小学生只能坐一次 bus 。因此,每个小学生到达目的地的时间,就是坐 bus 的时间+走路的时间,最短时间显然取决于坐 bus 路程最短的那人。那么,最优的情况应该就是,所有人坐 bus 的路程都一样,这样就能够保证最快的和最慢的所花的时间相同。
- #include <cstdio>
- #include <map>
- #include <set>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cmath>
- #include <algorithm>
- #include <cstring>
- #include <string>
- using namespace std;
- #define INF 0x3f3f3f3f
- typedef long long LL;
-
- int main()
- {
- int n,l,v1,v2,k;
- while(~scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k)){
- if(k>=n){
- printf("%.10lf\n",l*1.0/v2);
- continue;
- }
- int t=(n-1)/k;
- double s=v2*1.0/v1;
- double kk=(1+s)/(3+s);
- double temp=kk+t*(1-kk);
- temp=l*1.0/(temp*v1);
- printf("%.10lf\n",temp*(kk/s+t*(1-kk)));
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。