二分2.0(double)
来源:互联网 发布:点评10月的经济数据 编辑:程序博客网 时间:2024/06/07 04:52
The Meeting Place Cannot Be Changed CodeForces - 782B
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.
Example
Input
3
7 1 3
1 2 1
Output
2.000000000000
Input
4
5 10 3 2
2 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.
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;#include<cmath>int main(){int n;__int64 x[60000+5], v[60000+6];scanf("%d", &n);int i, j;for(i = 0; i < n; i++) scanf("%I64d", &x[i]); for(i = 0; i < n; i++) scanf("%I64d", &v[i]);double l, r, mid;l = 0;r = 1000000000;for(j = 0; j < 300; j++){mid = (l+r)/2;double left = 0, right = 1e18+5;for(i = 0; i < n; i++){if(x[i]<v[i]*mid) left = max(0.0, left);else left = max(x[i]-v[i]*mid, left);right = min(right, x[i]+v[i]*mid);}if(left<right) r = mid;else l = mid;}printf("%.12f\n", l);return 0;}
- 二分2.0(double)
- POJ2109 Power of Cryptography (高精度+二分) (可以double水過去)
- Uva 10984 Double NP-hard(二分图)
- (ZOJ) 3334 二分+贪心(二分double的写法)
- 对时间的二分 奔跑的xiaodao double + 精度
- soj 4392 double类型的使用和二分查找
- UVA 113-Power of Cryptography(二分+double处理大数据)
- 【二分查找】求一个double型数据的平方根
- 搜索入门之“二分查找”&&double运算精度问题-HDU2199
- hdu2199 Can you solve this equation? (二分+double精度)
- List(double linked)
- Java (Double-Check)
- Double
- Double
- double
- 这有错吗???(关于double&long double)
- String 转化成double(不用Double.parseDouble(str))
- double atof的实现(char型转double)
- Github上传本地代码
- CodeForces
- 光栅图形学算法--消隐算法
- Android -- 应用基础知识
- 传递函数
- 二分2.0(double)
- Java基础笔记整理---【02】JDK及JRE名词解释、程序开发步骤(笔记本)
- 接口 垃圾回收机制(GC)
- c# UILearning
- 分页前台展示备忘
- 关于售前、售后、产品、市场、销售几个部门职能的理解
- 同余方程-NOIP2012TGD2T1
- 菜鸟填坑
- 排序基础(一)