780B - The Meeting Place Cannot Be Changed
思路:
二分答案;
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define eps 1e-7
#define INF 1e18
#define maxn 60005 int n; double xi[maxn],sp[maxn]; bool check(double ti)
{
double l=-INF,r=INF;
for(int i=;i<=n;i++)
{
l=max(l,xi[i]-sp[i]*ti);
r=min(r,xi[i]+sp[i]*ti);
}
if(l<=r) return true;
else return false;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lf",&xi[i]);
for(int i=;i<=n;i++) scanf("%lf",&sp[i]);
double l=,r=1e9,ans;
while(l<=r)
{
double mid=(l+r)/2.0;
if(check(mid)) r=mid-eps,ans=mid;
else l=mid+eps;
}
printf("%.7lf",ans);
return ;
}