CodeForces 700A As Fast As Possible

时间:2023-03-09 17:05:22
CodeForces 700A As Fast As Possible

要保证总时间最短,因为总时间计的是最后一个人到达的时间,也就是最后一个人要求尽快到达,也就是说我们要让最后一个人乘车时间尽量多。再仔细想想可以发现每个人的乘车时间和走路时间都是一样的。

因此,可以二分每个人的乘车时间$m$,然后进行验证,如果发现某一个人的乘车时间不到$m$,那么$m$不可取,上界缩小;如果$m$可取,那么上界增大。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} int n,L,v1,v2,k; bool check(double m)
{
double x=; int p=n;
while()
{
p=p-min(p,k); double t=(1.0*L-x)/v2;
if(t<m) return ; if(p==) break;
x=x+v1*m; double tmp=m*(v2-v1)/(v1+v2);
x=x+tmp*v1;
}
return ;
} int main()
{
scanf("%d%d%d%d%d",&n,&L,&v1,&v2,&k);
double left=,right=1.0*L/v2,ans=;
int T=;
while(T--)
{
double m=(left+right)/;
if(check(m)) left=m,ans=m+(1.0*L-m*v2)/v1;
else right=m;
}
printf("%.6lf\n",ans);
return ;
}