日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 701D】As Fast As Possible(二分,模拟,数学公式)

發布時間:2023/12/10 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 701D】As Fast As Possible(二分,模拟,数学公式) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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,走路的速度為v1,公交車的速度v2(公交車只有一輛,且v1<v2),車中最多坐k人,每人最多做一次車,求所有人到終點的最小時間。?(1?≤?n?≤?10?000,?1?≤?l?≤?109,?1?≤?v1?<?v2?≤?109,?1?≤?k?≤?n)

解題報告:

因為最佳答案不一定是把所有人載到終點再回去載下一波人,且注意到時間符合單調性,可以二分。首先求出一共需要用多少波公交車(因為v1<v2,所以充分利用公交車肯定可以使得時間最短),然后維護當前所有人所在的位置,然后求出載的這一波人在當前二分的可用時間下可以最短用多久的公交車,就讓他用這么久的公交車,然后就讓公交車返程來載下一波人。注意統計時間的時候,公交車是不需要返程的,所以不需要加上這一部分時間。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; const double eps = 1e-8; ll n,k; double L,v1,v2; bool ok(double time) {ll all = n/k + (n%k>0);double pos=0,t=0;for(int i = 1; i<=all; i++) {double tmpt = (L-pos-(time-t)*v1)/(v2-v1);if(i == all) {t += tmpt;break;}double chepos = tmpt * v2;//車本次走的的最遠長度 double huit = (chepos-tmpt*v1)/(v1+v2); pos = pos + (tmpt+huit) * v1;t += tmpt+huit;}return t <= time; }int main() {cin>>n>>L>>v1>>v2>>k; double l = 0,r = L,mid,ans=r;int cnt=0;while(cnt++<500) {mid=(l+r)/2;if(ok(mid)) r = mid,ans=mid;else l = mid;} printf("%.8f\n",ans);return 0 ; }

?

總結

以上是生活随笔為你收集整理的【CodeForces - 701D】As Fast As Possible(二分,模拟,数学公式)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。