codeforces 700A As Fast As Possible

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

Input
5 10 1 2 5
Output
5.0000000000
Input
3 6 1 2 1
Output
4.7142857143

Hint

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 ,v1,v2,k,分别代表有n个小学生,要走L米的路,有两种出行方式,步行或者bus,步行速度时v1,bus速度v2,一辆bus每次最多载k个小学生,每个学生最多坐一次bus.问你所有

     学生都到达终点所用的最短时间。

分析 : 这道题是参考网上题解做的。首先要搞清楚一点 :最快的到达时间是所有学生一起到达终点,也就是说我们让bus先载k个学生走到一个地方,放下来这些学生,返回去载另外的学生,

   也就是我们二分寻找所用的总时间 t ,假设步行的花费时间时 t1,坐bus的时间是t2,因为每次只载k 个人,所以总共需要 载 K次,返回 k-1次。所以在二分时我们需要判断是否满足条件,使得

  乘车时间 × K + 返回时间 × (K -1)  <= t; 乘车的最短时间可以根据 : v2 * t2 - v1 *t2 = L - s (这里的s表示步行的距离) 返回时间 t3 = (v2 - v1 )* t2/(v2 + v1) (相遇问题推出)。

 1 /*************************************************************************
 2     > File Name: train.cpp
 3     > Author: 
 4     > Mail: 
 5     > Created Time: 2016年08月03日 星期三 10时19分00秒
 6  ************************************************************************/
 7 
 8 #include<iostream>
 9 #include<bits/stdc++.h>
10 using namespace std;
11 typedef long long ll;
12 const int INF = 1e9;
13 double l ,v1,v2;
14 int n,k;
15 
16 bool C(double x)
17 {
18     int K = n/k;
19     if(n%k != 0) K++;
20     double t1 = (l - x * v1)/(v2 - v1);
21     if(K * t1 + (K-1) * ((v2 - v1) * t1 / (v2 + v1) )  <= x)
22         return true;
23     return false;
24 }
25 
26 int main()
27 {
28     cin >> n >> l >> v1 >> v2 >> k;
29     double lb,ub;
30     lb = l / v2, ub = l / v1;
31     for(int i = 0; i < 100; i++)
32     {
33         double mid = (lb + ub)/2;
34         if(C(mid)) ub = mid;
35         else lb = mid;
36     }
37     printf("%.10lf\n",lb);
38     return 0;
39 }

 

posted @ 2016-08-03 13:50  PrayG  阅读(258)  评论(0编辑  收藏  举报