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. 路径正确下,Eclipse读取txt文件仍失败

    症状:使用Eclipse读取文件时,路径输入确认正确(前提!!!),但控制台总报错: 错误类型一: Exception in thread "main" java.io.FileN ...

  2. Git的安装使用和基本命令(一)

    版本控制系统是每一个程序员的必备神器,我相信任何一个程序员都要用到版本控制系统,它的强大之处我就不作解释了,在这我将Git(分布式版本控制系统)的安装使用和基本的命令给初学者介绍一下(在linux系统 ...

  3. 基于Intranet的零件库管理信息系统设计--part02

    昨天建了第一个子表,今天继续. 按照这个一个一个来: 轴承参数查询如下(来源:轴承查询型号网) 照这个来大概就是这么几个属性: 轴承主键,轴承名称,新型号,旧型号,内径,外径,宽度,Cr,Cor(话说 ...

  4. Linux-ubuntu安装过程讲解

    前言也不准备介绍Linux是什么,为什么要安装ubuntu?相信你能够看到这篇文章也知道自己想要做什么. 一,准备工具 1.VMwareWorkstation虚拟机 下载地址:https://my.v ...

  5. (转)关闭iptables和SELinux

    1. 关闭SELinux setenforce 0   #临时关闭 编辑/etc/selinux/config,找到SELINUX 行修改成为:SELINUX=disabled:     #永久关闭, ...

  6. 解决codeblock不能运行的问题

    codeblock 编译失败 软件 IDE codeblock这软件的确不错,但是除此安装使用就会不小心入坑.你是不是满心欢喜的下载好codeblock,敲入代码,点击运行的时候却总是没反应呢? 如果 ...

  7. centos7 部署openstf

    1.安装nodejs,版本需大于6.9(写稿时使用的6.9,7.7.4版本会无法安装zmq): 2.安装android sdk(详细略,百度一大堆),注意必须将platform-tool配置到环境变量 ...

  8. Java对象的内存模型(一)

    前言 新人一枚,刚刚入门编程不久,各方面都在学习当中,博文有什么错误的地方,希望我们可以多多交流! 最近,在开发App后台过程中,需要将项目部署到云服务器上.而云服务器的内存大小却只有1G.要如何做到 ...

  9. 老李分享:持续集成学好jenkins之解答疑问

    老李分享:持续集成学好jenkins之解答疑问   poptest(www.poptest.cn)在培训的过程中使用jenkins搭建持续集成环境,让学员真正交流持续集成到底是什么,怎么去做的. Je ...

  10. Poptest学员之当小厨师变成测试开发工程师

    没开玩笑,这是我们的真实案例.做培训以来,各行各业转行做测试的学员见得太多了.修车的.客服的.销售的.司机的.医护的.前台的等等.职位虽然不分贵贱,但是薪资却分多少.每个人心中都有让家人和自己过上好日 ...