CodeForces

来源:互联网 发布:淘宝国内lolita品牌 编辑:程序博客网 时间:2024/06/06 17:50

题目链接:传送门。

The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north.You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.

Input

The first line contains single integer n (2 ≤ n ≤ 60 000) — the number of friends.The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters.The third line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters per second.

Output

Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road.Your answer will be considered correct, if its absolute or relative error isn't greater than 10 - 6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if holds.

Examples
Input

37 1 31 2 1

Output

2.000000000000

Input

45 10 3 22 3 2 4

Output

1.400000000000

Note

In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.

【题意】

有n个人要聚会,每个人有一个坐标(所有人都在x轴上),和自己对应的速度,现在要你选择一个点,使得所有的人都到这个点去,并且使得最后一个到的人用时最少。问你最少用时是多少。

【分析】

做法很多,基本都离不开二分,我用的是比较简单的二分答案。直接二分出一个答案,然后判断每个点在这个时间里面是否能到同一个点去。这里我们转化一下,因为有了时间,所以某个人能到的地方就是一个区间,然后我们判断所有的区间是否有交集,如果有交集就说明所有点都能到达这个点。然后二分就行了。

【代码】

#include<iostream>#include<cstdio>#include<cstring>#include<string.h>#include<algorithm>#include<vector>#include<cmath>#include<stdlib.h>#include<time.h>#include<stack>#include<set>#include<map>#include<queue>#include<sstream>using namespace std;#define rep0(i,l,r) for(int i = (l);i < (r);i++)#define rep1(i,l,r) for(int i = (l);i <= (r);i++)#define rep_0(i,r,l) for(int i = (r);i > (l);i--)#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)#define MS0(a) memset(a,0,sizeof(a))#define MS_1(a) memset(a,-1,sizeof(a))#define MSinf(a) memset(a,0x3f,sizeof(a))#define MSfalse(a) memset(a,false,sizeof(a))#define pin1(a) printf("%d",(a))#define pin2(a,b) printf("%d %d",(a),(b))#define pin3(a,b,c) printf("%d %d %d",(a),(b),(c))#define pll1(a) printf("%lld",(a))#define pll2(a,b) printf("%lld %lld",(a),(b))#define pll3(a,b,c) printf("%lld %lld %lld",(a),(b),(c))#define pdo1(a) printf("%f",(a))#define pdo2(a,b) printf("%f %f",(a),(b))#define pdo3(a,b,c) printf("%f %f %f",(a),(b),(c))#define huiche puts("")#define inf 0x3f3f3f3f#define lson (ind<<1),l,mid#define rson ((ind<<1)|1),mid+1,r#define uint unsigned inttypedef pair<int,int> PII;#define A first#define B second#define pb push_back#define mp make_pair#define ll long long#define eps 1e-8#define pi acos(-1.0)inline void read1(int &num) {    char in;    bool IsN=false;    in=getchar();    while(in!='-'&&(in<'0'||in>'9')) in=getchar();    if(in=='-') {        IsN=true;        num=0;    } else num=in-'0';    while(in=getchar(),in>='0'&&in<='9') {        num*=10,num+=in-'0';    }    if(IsN) num=-num;}inline void read2(int &a,int &b) {    read1(a);    read1(b);}inline void read3(int &a,int &b,int &c) {    read1(a);    read1(b);    read1(c);}inline void read1(ll &num) {    char in;    bool IsN=false;    in=getchar();    while(in!='-'&&(in<'0'||in>'9')) in=getchar();    if(in=='-') {        IsN=true;        num=0;    } else num=in-'0';    while(in=getchar(),in>='0'&&in<='9') {        num*=10,num+=in-'0';    }    if(IsN) num=-num;}inline void read2(ll &a,ll &b) {    read1(a);    read1(b);}inline void read3(ll &a,ll &b,ll &c) {    read1(a);    read1(b);    read1(c);}inline void read1(double &num) {    char in;    double Dec=0.1;    bool IsN=false,IsD=false;    in=getchar();    while(in!='-'&&in!='.'&&(in<'0'||in>'9'))        in=getchar();    if(in=='-') {        IsN=true;        num=0;    } else if(in=='.') {        IsD=true;        num=0;    } else num=in-'0';    if(!IsD) {        while(in=getchar(),in>='0'&&in<='9') {            num*=10;            num+=in-'0';        }    }    if(in!='.') {        if(IsN) num=-num;        return ;    } else {        while(in=getchar(),in>='0'&&in<='9') {            num+=Dec*(in-'0');            Dec*=0.1;        }    }    if(IsN) num=-num;}inline void read2(double &a,double &b) {    read1(a);    read1(b);}inline void read3(double &a,double &b,double &c) {    read1(a);    read1(b);    read1(c);}///-----------------------------------------------------------------------------------------------------------int n;const int maxm = 6e4+10;pair<int,int>poi[maxm];double cal(double t){    double l = -1e9,r = 1e18;    rep0(i,0,n)    {        double lx = poi[i].first-poi[i].second*t;        double rx = poi[i].first+poi[i].second*t;        l = max(l,lx);        r = min(r,rx);    }    if(r<l) return false;    return true;}int main() {//    freopen("in.txt","r",stdin);    while(scanf("%d",&n)!=EOF)    {        rep0(i,0,n) read1(poi[i].first);        rep0(i,0,n) read1(poi[i].second);        double l = 0,r = 1e9+10;        while(r-l>1e-6)        {            double mid = (l+r)/2;            if(cal(mid))                r = mid;            else l = mid;        }        printf("%.10f\n",l);    }    return 0;}