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 ...
随机推荐
- IE10去掉input的type=”text”输入内容时出现的小叉号(X)和type=”password”出现的小眼睛图标
最近在做一个后台管理系统项目,遇到以下两个问题: 1.从IE 10开始,type="text" 的 input 在用户输入内容后,会自动产生一个小叉号(X),方便用户点击清除已经输 ...
- 【Python系列】Python自动发邮件脚本-html邮件内容
缘起 这段时间给朋友搞了个群发邮件的脚本,为了防止进入垃圾邮件,做了很多工作,刚搞完,垃圾邮件进入率50%,觉得还不错,如果要将垃圾邮件的进入率再调低,估计就要花钱买主机了,想想也就算了,先发一个月, ...
- UWP Composition API - New FlexGrid 锁定行列
如果之前看了 UWP Jenkins + NuGet + MSBuild 手把手教你做自动UWP Build 和 App store包 这篇的童鞋,针对VS2017,需要对应更新一下配置,需要的童鞋点 ...
- 通过composer管理工具安装laravel
当安装好composer管理工具后,将composer的bin目录添加至环境变量中(PATH),方便在任意目录下执行composer命令. 方法1:我们通过laravel工具安装laravel 首先, ...
- oracle索引(转)
引,索引的建立.修改.删除 2007-10-05 13:29 来源: 作者: 网友评论 0 条 浏览次数 2986 索引索引是关系数据库中用于存放每一条记录的一种对象,主要目的是加快数据的读取速度和完 ...
- [LeetCode] Zuma Game 题解
题目 题目 Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B ...
- 【Electron】Electron开发入门(四):操作PC端文件系统
一.调用PC端默认方式打开本地文件 在main.js里 // 打开系统本地文件或者网页链接 const {shell} = require('electron'); // Open a local f ...
- Mybatis基础学习(一)—初识MyBatis
一.MyBatis是什么? MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google co ...
- js的apply()与call()的区别
1.各自对应的不同的语法: /*apply()方法*/ function.apply(thisObj[, argArray]) /*call()方法*/ function.call(thisObj[, ...
- [UWP]了解模板化控件(4):TemplatePart
1. TemplatePart TemplatePart(部件)是指ControlTemplate中的命名元素.控件逻辑预期这些部分存在于ControlTemplate中,并且使用protected ...