The Meeting Place Cannot Be Changed

Problem Description

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

Examples Output

2.000000000000

Examples Input

4
5 10 3 2
2 3 2 4

Examples 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.

题目链接:http://codeforces.com/problemset/problem/782/B


题意:一条线上有n个人,每个人一个坐标值xi,每个人有一个最大行走速度vi,问如果要让这n个人走到线上某一个点,最少需要多少时间。(百度的)

思路:(自己的)

知道这个后就明朗了,我们只需要利用3分法(为什么用3分法 o.o 学长说的)循环去缩小那个最小的时间范围。

三分的代码很简洁明了,自己看楼。

接着要解决的一个难题 就是 怎么判断 某t 时间内,所有点是否都能移动到某个点上:

思路:

= =。图是丑了点。 每个圈都代表每个人在 某t 时间内的可以的运动范围。

如果交集不为空,则 在t时间内能够移动一点上。

代码实现见函数  bool run(double time);

ps: 最后输出的时候 用cout<<r<<endl; 或printf("%lf\n",r); 会WA。

因为 这样输出是默认 输出保留小数点6位后输出 即四舍五入 到小数点后6位再输出的。。。坑死我了。。。


AC代码如下:time:139ms

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN=+;
const double eps=0.000001;
struct type_1
{
double x,v;//x 为人的坐标 v为速度
}people[MAXN];
int n=;
bool cmp(type_1 a,type_1 b)
{
return a.x<b.x;
}
void time(double &maxtime)//求[0,maxtime]中的maxtime
{
maxtime=(people[n-].x-people[].x)/people[].v;
double m;
for(int i=;i<n;i++)
{
m=max((people[i].x-people[].x)/people[i].v,(people[n-].x-people[i].x)/people[i].v);
if(m>maxtime)
maxtime=m;
}
}
bool run(double time)//判断t时间内是否都能到某个点
{
double x1,x2,temp1,temp2;
x1=people[].x-people[].v*time;
x2=people[].x+people[].v*time;
for(int i=;i<n;i++)
{
temp1=people[i].x-people[i].v*time;
temp2=people[i].x+people[i].v*time;
if(temp1>x1)
x1=temp1;
if(temp2<x2)
x2=temp2;
if(x1>x2)
return false;
}
return true;
} int main()
{
cin>>n;
for(int i=;i<n;i++)
scanf("%lf",&people[i].x);
for(int i=;i<n;i++)
scanf("%lf",&people[i].v);
sort(people,people+n,cmp);
double l=,r;//时间范围[0,maxtime]
time(r);
double o1,o2;//三分后的两个点
bool bo1,bo2;
while(l+eps<r)//缩小到精度以内 结束循环。
{
o1=(*l+r)/;//时间三分后的time1
o2=(*r+l)/;//时间三分后的time2
//printf("[%.10lf,%.10lf] [%.10lf,%.10lf]\n",o1,o2,l,r);
bo1=run(o1);//纪录o1时间内所有点能否到达一点的真假
bo2=run(o2);
//cout<<"-"<<bo1<<" "<<bo2<<"-"<<endl;
if(bo2==false)
l=o2;
else
{
r=o2;
if(bo1==true)
r=o1;
else
l=o1;
}
}
printf("%.10llf\n",r);//注意 在这里WA了半个多小时,最后加了 (.10) 后终于AC。
//cout<<r<<endl;
return ;
}

2017-03-09 01:16:21

codeforces 782B The Meeting Place Cannot Be Changed (三分)的更多相关文章

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

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

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

                                                                   B. The Meeting Place Cannot Be Change ...

  3. codeforces 782B - The Meeting Place Cannot Be Changed

    time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standa ...

  4. CodeForces 782B The Meeting Place Cannot Be Changed (二分)

    题意:题意:给出n个人的在x轴的位置和最大速度,求n个人相遇的最短时间. 析:二分时间,然后求并集,注意精度,不然会超时. 代码如下: #pragma comment(linker, "/S ...

  5. CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)

    题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间. 分析: 1.二分枚举最短时间即可. 2.通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜 ...

  6. 782B. The Meeting Place Cannot Be Changed 二分 水

    Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...

  7. 782B The Meeting Place Cannot Be Changed(二分)

    链接:http://codeforces.com/problemset/problem/782/B 题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...

  8. 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 ...

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

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

随机推荐

  1. 首个写博客的Android任务

    任务1 单击按钮图片选择器 使用TextView,RadioGroup,RadioButton完成. 设置单击按钮选择显示花朵. 首先设置了页面布局 <LinearLayout xmlns:an ...

  2. C++移位运算符详解

    移位运算符包括左移"<<"和右移">>" 左移运算符<<: 1.无符号 语法格式:需要移位的数字<<移位的次数n ...

  3. Java字节流在Android中的使用

    引言:项目开发有时会使用上传文件到服务器,再从服务器取数据显示到本地这一过程:或者输入一段文字,再把文字显示出来.这个过程都用到了IO流. IO流分为字符流(Reader\Writer)和字节流(In ...

  4. javascript . 05 json的组成、for...in 遍历对象、简单数据类型与复杂数据类型的传值与传址、内置对象

    对象字面量  JSON var obj = { aaa :999}; var json={"aaa":999,"bbb":888}; "kay&quo ...

  5. Jmeter-线程组

    1.Sampler 取样器(Sampler)是性能测试中向服务器发送请求,记录响应信息,记录响应时间的最小单元,JMeter 原生支持多种不同的sampler , 如 HTTP Request Sam ...

  6. MYSQL性能优化--分库分表

    1.分库分表 1>纵向分表 将本来可以在同一个表的内容,人为划分为多个表.(所谓的本来,是指按照关系型数据库的第三范式要求,是应该在同一个表的.) 分表理由:根据数据的活跃度进行分离,(因为不同 ...

  7. express创建网站

    Express 在初始化一个项目的时候需要指定模板引擎,默认支持Jade和ejs. 这里我们使用ejs模板引擎:(关于ejs的介绍可以先从百科里面了解一个大概)EJS是一个JavaScript模板库, ...

  8. Linux环境下的IDE,极大提升编程效率

    "一个真正的程序员是不用IDE(译者注:集成开发环境)的,他们都是用带着某某插件的文本编辑器来写代码."我们总能在某些地方听到此类观点.然 而,尽管越来越多的人同意这样的观点,但是 ...

  9. ajax 实现修改功能

    这段时间在做项目,发现自己忘得好快呀,幸亏有博客园帮我记着呢,整理博客园简直不要太重要了哦  因为做的是一个内部管理系统,只用了一个主页面,所有的都不允许整个网页刷新,所以我们只能用ajax 来做,当 ...

  10. 老李推荐:第2章3节《MonkeyRunner源码剖析》了解你的测试对象: NotePad窗口Activity之NoteEditor简介

    老李推荐:第2章3节<MonkeyRunner源码剖析>了解你的测试对象: NotePad窗口Activity之NoteEditor简介   我们在增加和编辑一个日记的时候会从NotesL ...