AC日记——The Meeting Place Cannot Be Changed codeforces 780b

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=1;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=1;i<=n;i++) scanf("%lf",&xi[i]);
    for(int i=1;i<=n;i++) scanf("%lf",&sp[i]);
    double l=0,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 0;
}

 

posted @ 2017-05-11 10:50  IIIIIIIIIU  阅读(329)  评论(0编辑  收藏  举报