首页 技术 正文
技术 2022年11月7日
0 收藏 410 点赞 945 浏览 2851 个字

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.

ExamplesInput

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.

分析:参考自http://blog.csdn.net/libin66/article/details/52004623

   首先最优情况下应有每个人坐公交时间和走路时间都相等(保证同时到达)。

   这些人可以分为cnt=(n-k+1)/k部分;

   设每个人坐bus路程L1,第二波人遇见bus时时间为T,则有(V1+V2)*T=2L1;

   那么第二波人走了d=TV1=2L1V1/(V1+V2);

   以后每一波人坐bus前都会继续多走d的路程,那么最后一波人走的路程(cnt-1)*d=L-L1;

    (保证坐bus恰好到达终点)

   则解得L1=L*(V1+V2)/(2*cnt*V1-V1+V2),总时间t=L1/V2+(L-L1)/V1;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <ext/rope>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=1e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,l,v1,v2,k;
int main()
{
int i,j,t;
cin>>n>>l>>v1>>v2>>k;
int cnt=(n+k-)/k;
double bus_path=1.0*l*(v1+v2)/(*cnt*v1-v1+v2);
double ans=bus_path/v2+(l-bus_path)/v1;
printf("%.10f\n",ans);
//system ("pause");
return ;
}

补二分做法:二分结束时间,然后根据方法一算出最后一组在期望时间能够走的总路程,与目标路程比较;

代码:

#include <bits/stdc++.h>
using namespace std;
int n,m,l,v1,v2;
int main()
{
int i,j,k,t;
cin>>n>>l>>v1>>v2>>k;
int cnt=(n+k-)/k;
double tl=,tr=(double)l/v1;
while(tr-tl>1e-)
{
double mid=(tl+tr)/;
double l1=(mid-(double)l/v1)*v1*v2/(v1-v2),p=(cnt-)**l1/(v1+v2)*v1+l1;
if(p<=l)tr=mid;
else tl=mid;
}
printf("%.10f\n",tl);
//system("pause");
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905