题意:

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
3
7 1 3
1 2 1
output
2.000000000000
input
4
5 10 3 2
2 3 2 4
output
1.400000000000

思路:

二分,注意控制精度。

实现:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
struct node
{
double pos;
double speed;
};
node a[];
int n;
double minn, maxn;
bool check(double t)
{
minn = a[].pos - t * a[].speed;
maxn = a[].pos + t * a[].speed;
for (int i = ; i < n; i++)
{
double tmp_l = a[i].pos - t * a[i].speed;
double tmp_r = a[i].pos + t * a[i].speed;
minn = max(minn, tmp_l);
maxn = min(maxn, tmp_r);
}
return maxn - minn >= 1e-;
} double solve()
{
double l = 0.0, r = , res = ;
for (int i = ; i < ; i++)
{
double mid = (l + r) / 2.0;
if (check(mid))
{
r = mid;
res = mid;
}
else
{
l = mid;
}
}
return res;
} int main()
{
cin >> n;
for (int i = ; i < n; i++)
{
cin >> a[i].pos;
}
for (int i = ; i < n; i++)
{
cin >> a[i].speed;
}
cout << setprecision() << solve() << endl;
return ;
}

CF782B The Meeting Place Cannot Be Changed的更多相关文章

  1. codeforces 782B The Meeting Place Cannot Be Changed (三分)

    The Meeting Place Cannot Be Changed Problem Description The main road in Bytecity is a straight line ...

  2. code force 403B.B. The Meeting Place Cannot Be Changed

    B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...

  3. Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)

    The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...

  4. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed

    地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...

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

    780B - The Meeting Place Cannot Be Changed 思路: 二分答案: 代码: #include <cstdio> #include <cstrin ...

  6. Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)

    题目链接 The Meeting Place Cannot Be Changed 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...

  7. codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

                                                                   B. The Meeting Place Cannot Be Change ...

  8. CodeForce-782B The Meeting Place Cannot Be Changed(高精度二分)

    https://vjudge.net/problem/CodeForces-782B B. The Meeting Place Cannot Be Changed time limit per tes ...

  9. B. The Meeting Place Cannot Be Changed

    B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...

随机推荐

  1. mysql表分区 partition

    表分区 partition 当一张表的数据非常多的时候,比如单个.myd文件都达到10G, 这时,必然读取起来效率降低. 可不可以把表的数据分开在几张表上? 1: 从业务角度可以解决.. (分表,水平 ...

  2. IE9不能直接引用Console

    问题: 公司有个项目,功能很简单,读取业务数据,展示在页面上. 一个很简单的问题,却因为目标浏览器是IE9,卡了三天. 前端给的反馈是: 在IE9下,程序一会儿对,一会儿不对--第一次刷不出来,多刷几 ...

  3. html5--3.1 form元素

    html5--3.1 form元素 学习要点 form元素及其属性 form元素 用来定义一个表单,是建立表单的基础元素,(就类似定义表格的table) 表单的其他元素包含在form元素中,其主要子元 ...

  4. Viewpager animation duration setting

    private void animatePagerTransition(final boolean forward) { ValueAnimator animator = ValueAnimator. ...

  5. MySQL 优化之 EXPLAIN 关键字

    MySQL查询优化之explain的深入解析 0. 准备 首先执行如下的 sql 语句: CREATE TABLE IF NOT EXISTS `article` (`id` int(10) unsi ...

  6. setTimeout的第三个参数

    最熟悉的地方,往往会忽略一些细节.就比如 setTimeout 函数,做前端开发的同学都会很熟悉这个函数,经常使用这个函数,但是知道这个函数还有第三个参数的小伙伴可能就不多了.起码我在阅读阮老师的 e ...

  7. [Selenium] 操作 警告框、提示框、确认框

    以如下页面为例: http://sislands.com/coin70/week1/dialogbox.htm 示例代码: pachage com.learningselenium.normalweb ...

  8. 【CAIOJ1177】 子串是否出现

    [题目链接] 点击打开链接 [算法] KMP [代码] #include<bits/stdc++.h> using namespace std; #define MAXA 1000010 ...

  9. 洛谷P3354 [IOI2005]Riv 河流——“承诺”DP

    题目:https://www.luogu.org/problemnew/show/P3354 状态中要记录一个“承诺”,只需相同承诺之间相互转移即可: 然后就是树形DP的套路了. 代码如下: #inc ...

  10. css原生变量 var

    css 变量的支持情况: 在pc端支持还不错,ie不支持,移动端也不支持,大概这就是css变量没有广泛使用的原因吧 CSS预编译工具Sass/Less/Stylus的便捷之处就是可以定义变量,方便代码 ...