NWU_ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <bitset>
 6 #include <vector>
 7 #include <queue>
 8 #include <stack>
 9 #include <cmath>
10 #include <list>
11 #include <set>
12 #include <map>
13 #define rep(i,a,b) for(int i = a;i <= b;++ i)
14 #define per(i,a,b) for(int i = a;i >= b;-- i)
15 #define mem(a,b) memset((a),(b),sizeof((a)))
16 #define FIN freopen("in.txt","r",stdin)
17 #define FOUT freopen("out.txt","w",stdout)
18 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
19 #define mid ((l+r)>>1)
20 #define ls (id<<1)
21 #define rs ((id<<1)|1)
22 #define INF 0x3f3f3f3f
23 using namespace std;
24 typedef long long LL;
25 typedef pair<int, int> PIR;
26 const int N = 6e4+5;
27 
28 int n;
29 double x[N], v[N];
30 bool judge(double md){
31     double l = 0, r = 1e9*1.0;
32     rep (i, 1, n) {
33         double ll = x[i]-v[i]*md, rr = x[i]+v[i]*md;
34         if(ll < l && ll > r && rr < l && rr > r)    return false;
35         l = max(ll, l);
36         r = min(rr, r);
37         if(l > r)    return false;
38     }
39     return true;
40 }
41 int main()
42 {
43     //FIN;
44     while (scanf("%d", &n) != EOF) {
45         rep (i, 1, n)    scanf("%lf", &x[i]);
46         rep (i, 1, n)    scanf("%lf", &v[i]);
47         double low = 0, high = 1e9*1.0, ans = 0;
48         rep (i, 1, 300) {
49             double md = (low+high)/2;
50             if(judge(md))    { high = md-1; ans = md; }
51             else low = md+1;
52         }
53         printf("%.6lf\n", ans);
54     }
55     return 0;
56 }
View Code

 

posted on 2017-03-13 16:02  NWU_ACM  阅读(152)  评论(0编辑  收藏  举报