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 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 (三分)的更多相关文章
- Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)
题目链接 The Meeting Place Cannot Be Changed 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...
- codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)
B. The Meeting Place Cannot Be Change ...
- 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 ...
- CodeForces 782B The Meeting Place Cannot Be Changed (二分)
题意:题意:给出n个人的在x轴的位置和最大速度,求n个人相遇的最短时间. 析:二分时间,然后求并集,注意精度,不然会超时. 代码如下: #pragma comment(linker, "/S ...
- CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)
题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间. 分析: 1.二分枚举最短时间即可. 2.通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜 ...
- 782B. The Meeting Place Cannot Be Changed 二分 水
Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...
- 782B The Meeting Place Cannot Be Changed(二分)
链接:http://codeforces.com/problemset/problem/782/B 题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...
- 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 ...
- AC日记——The Meeting Place Cannot Be Changed codeforces 780b
780B - The Meeting Place Cannot Be Changed 思路: 二分答案: 代码: #include <cstdio> #include <cstrin ...
随机推荐
- python服务器环境搭建(2)——安装相关软件
在上一篇我们在本地的虚拟服务器上安装好CentOS7后,我们的python web服务.自定义的python service或python脚本需要在服务器上运行,还需要在服务器安装各种相关的软件才行, ...
- 分离数据库时出错:无法对数据库'XXX' 执行删除,因为它正用于复制"的解决方法
出现的原因是要分离的数据库是一个发布订阅的数据库.因为正在复制,所以无法脱机. 解决办法是停止发布订阅,或者删掉它..再分离.有部分情况是在复制目录下并没有看到发布订阅. 有可能是因为以前建立发布订阅 ...
- 说说JAVA之网络编程 - 爬虫
首先总结一下学习过程中所需要的类: URL类 - openConnection() URLConnection类 - connection() getInputStream() BufferedRea ...
- 用C写一个web服务器(二) I/O多路复用之epoll
.container { margin-right: auto; margin-left: auto; padding-left: 15px; padding-right: 15px } .conta ...
- 提交任务到Spark
1.场景 在搭建好Hadoop+Spark环境后,现准备在此环境上提交简单的任务到Spark进行计算并输出结果.搭建过程:http://www.cnblogs.com/zengxiaoliang/p/ ...
- 【一通百通】c/php的printf用法
1.先说说PHP printf()函数: printf()函数的调用格式为: printf("<格式化字符串>", <参量表>); %d 十进制有符号整数 ...
- 百度cdn资源公共库共享及常用开发接口
CDN公共库是指将常用的JS库存放在CDN节点,以方便广大开发者直接调用 网站:http://cdn.code.baidu.com/ 常用资源: jquery: http://libs.baidu.c ...
- PRINCE2的发展情况是什么样
英国皇家特许培训机构AXELOS近期公布了一份调查结果,调查共有172位项目经理参与,其结果展示了未来全球趋势,对项目经理未来的职业形态和对他们必备技能的影响. 未来的项目管理职业 调查结果同时给 ...
- rsync+inotify实现文件同步更新(配置)
linux下为了数据安全或者网站同步镜像,不得不考虑一些实时备份的问题,这篇linux下通过rsync+inotify 实现数据实时备份配置过程记录下来,防止遗忘配置过程记录下来,防止遗忘!如有建议技 ...
- POST和GET的详细解释以及区别
Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...