题意:

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. Spring Boot 整合Filter

    两种方法 方法一: 正常创建好Filter类,配置完成 package clc.user.filter; import javax.servlet.Filter; import javax.servl ...

  2. 数据结构之 排序---折半插入排序(时间复杂度 O(nlog2 n) )

    排序 Time Limit: 1000MS Memory limit: 32678K 题目描述 给你N(N<=100)个数,请你按照从小到大的顺序输出. 输入 输入数据第一行是一个正整数N,第二 ...

  3. 织梦dedecms中修改标题与简略标题长度的方法

    本文介绍了dedecms中修改标题与简略标题长度的方法,进入dedecms后台,系统——系统基本参数——其他选项——文档标题最大长度——在这修改为200或更大. 一.修改标题 进入dedecms后台, ...

  4. 一题多解 —— linux 日志文件(log)reload 重新载入

    1. tail -F 等同于–follow=name –retry,根据文件名进行追踪,并保持重试,即该文件被删除或改名后,如果再次创建相同的文件名,会继续追踪 也即可以间接实现从日志文件末尾,不断载 ...

  5. Burpsuite实验一

    一.实验准备 win7系统 burpsuite 二.实验目的 进行重放攻击,观察结果 三.实验内容 本次实验并没有采取在虚拟机下进行,而是直接在win7系统中进行.首先配置一下环境,选择你常用的浏览器 ...

  6. vue之安装配置

    直接上图

  7. Educational Codeforces Round 24 CF 818 A-G 补题

    6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子, ...

  8. laravel5.2数据库基本操作

    laravel5.2数据库基本操作 百牛信息技术bainiu.ltd整理发布于博客园 use Illuminate\Database\Eloquent\Model; use Illuminate\Da ...

  9. node npm 总结

    是nodejs的软件包管理器,用于node插件管理 npm install <name> [-g] [--save -dev] name:安装模块的名称 -g:全局安装 --save:将保 ...

  10. Docker学习笔记(转自培训ppt)