地址:http://codeforces.com/contest/782/problem/B

题目:

B. The Meeting Place Cannot Be Changed
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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
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 <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e5+;
const int mod=1e9+; int n,ff;
double v[K],pos[K];
double l,r,x,y,mid; bool check(double t)
{
x=0.0,y=1e9;
for(int i=;i<=n;i++)
{
x=max(x,pos[i]-t*v[i]);
y=min(y,pos[i]+t*v[i]);
}
return y>=x||abs(y-x)<eps;
}
int main(void)
{
cin>>n;
for(int i=;i<=n;i++)
cin>>pos[i];
for(int i=;i<=n;i++)
cin>>v[i];
l=0.0,r=1e9;
for(int i=;i<=;i++)
{
mid=(r+l)/2.0;
if(check(mid)) r=mid;
else l=mid;
}
printf("%.6f\n",(r+l)/2.0);
return ;
}

Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed的更多相关文章

  1. 【三分】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed

    三分显然,要注意EPS必须设成1e-6,设得再小一点都会TLE……坑炸了 #include<cstdio> #include<algorithm> #include<cm ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  3. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map

    A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...

  5. 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E

    http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...

  6. 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D

    http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...

  7. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab

    地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...

  8. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons

    地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...

  9. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks

    地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seco ...

随机推荐

  1. HDU2586.How far away ?——近期公共祖先(离线Tarjan)

    http://acm.hdu.edu.cn/showproblem.php?pid=2586 给定一棵带权有根树,对于m个查询(u,v),求得u到v之间的最短距离 那么仅仅要求得LCA(u,v),di ...

  2. 怎样安装解压版MySQL

    第一步: 解压包. 第二步:引入MySQL的bin路径. 第三步: 在cmd下敲入 mysqld -install 第四步:启动服务 net start mysql 第五步:空password登录 m ...

  3. Java千百问_05面向对象(011)_引用传递和值传递有什么差别

    点击进入_很多其它_Java千百问 1.什么是值传递 值传递,是将内存空间中某个存储单元中存放的值,传送给还有一个存储单元.(java中的存储单元并不是物理内存的地址,但具有相关性) 比如: //定义 ...

  4. sap screen design

    定义屏幕:     SAP 系统中的屏幕包含:         标准屏幕:         选择屏幕:         列表输出屏幕: 1. 标准屏幕必须隶属于一个类型为 L, M 或 F 的ABAP ...

  5. cocos中lua使用shader实例

    local prog = cc.GLProgram:create("res/shader/light2d.vsh","res/shader/light2d.fsh&quo ...

  6. 将java项目发布到本地的linux虚拟机上

    1.首先安装虚拟机,这里就不介绍了. 2.然后要我下载了一个WinSCP用于windows和虚拟机之间的文件传输. 首先获得虚拟机的ip: 必须保持连接, 如果断开ip就是这样的 3.传输文件 将jd ...

  7. iOS-多线程的底层实现

    (1)首先回答什么是线程 1个进程要想执行任务,必须得有线程.线程是进程的基本执行单元,一个进程(程序)的所有任务都在线程中执行 (2)什么是多线程 1个进程中可以开启多条线程,每条线程可以并行(同时 ...

  8. 如何把IOS应用,发给别人测试?

    ios应用,除了用XCODE连接真实设备调试以外,也可以制作ipa安包,发给别人测试.下面是具体步骤: 1. 把要测试的设备标识添加到你苹果开发账号的调试设备里.(可以用xcode或者itools查看 ...

  9. sort命令与cat区别

    25.1 由于sort默认是把结果按照行排序后输出到标准输出,所以需要用重定向才能将结果写入文件,形如sort filename > newfile[root@shiyan a]# cat a. ...

  10. mybatis的一对多,多对一,以及多对对的配置和使用

    1.本文章是无意中看见易百教程的Mybatis教程才注意到这个问题,平时都仅仅是在用CRUD,忽略了这方面的问题,真实十分羞愧   2.首先我们开始对mybatis的一对多的探究   根据这个应用场景 ...