题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间。

分析:

1、二分枚举最短时间即可。

2、通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜索范围。

3、相当于二分枚举找右临界线,符合要求的点都在右边。

4、通过给二分一个查找次数的上界,eg:k=200,而不是dcmp(l, r)<=0,后者会tle。

5、检查是否有交集,就是以第一个点的最大移动区间为标准,不断与其他区间取交集并更新再继续比较。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 60000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN], v[MAXN];
int n;
bool judge(double t){
double tmpl = (double)a[0] - (double)v[0] * t;
double tmpr = (double)a[0] + (double)v[0] * t;
for(int i = 1; i < n; ++i){
double l = (double)a[i] - (double)v[i] * t;
double r = (double)a[i] + (double)v[i] * t;
if(dcmp(tmpl, r) > 0 || dcmp(tmpr, l) < 0) return false;
if(dcmp(l, tmpl) > 0) tmpl = l;
if(dcmp(r, tmpr) < 0) tmpr = r;
}
return true;
}
double solve(){
double l = 0, r = (double)1e9;
int k = 200;
while(k--){
double mid = (l + r) / 2;
if(judge(mid)) r = mid;
else l = mid + eps;
}
return r;
}
int main(){;
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
for(int i = 0; i < n; ++i){
scanf("%d", &v[i]);
}
printf("%.12lf\n", solve());
return 0;
}

  

CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)的更多相关文章

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

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

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

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

                                                                   B. The Meeting Place Cannot Be Change ...

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

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

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

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

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

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

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

  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. mysql#自定义序列

    原文 mysql主键不用自增数字的时候,可以参考如下方式,我抄来的. -- 创建公共的序列表 DROP TABLE IF EXISTS t_common_sequence; CREATE TABLE ...

  2. 1.Neo4j简介(Neo4j系列)

    简介 Neo4j是一个高性能.高可靠性.可扩展.支持ACID事务的图数据库,它基本由Java语言实现,支持数据平台的平滑扩展和过渡,同时能够在多种系统上完成部署,它使用Cypher查询语言对数据进行增 ...

  3. 前端学习笔记系列一:3 Vue中的nextTick

    一.示例 先来一个示例了解下关于Vue中的DOM更新以及nextTick的作用. 模板 <div class="app"> <div ref="msgD ...

  4. freemarker技术入门例子(结合struts2)

    由于最近项目里面要求要使用freemarker技术来做展现层,所以在网上搜索了好多资料,基础知识是看了李刚原来写的那本<struts2权威指南>.一直想在网上找一个很基础的例子来入门,但是 ...

  5. linux下mysql允许远程连接

    1. MySql安装教程 https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html 默认情况下mysq的 roo ...

  6. 【Winform】键 盘 事 件

    private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e) { , (, (, (, ( }; //回车 Backsp ...

  7. 说说mysql和oracle他门的分页查询,分别是怎么实现的?

    MySQL: 1.MySQL数据库实现分页比较简单,提供了 LIMIT函数.一般只需要直接写到sql语句后面就行了. 2.LIMIT子 句可以用来限制由SELECT语句返回过来的数据数量,它有一个或两 ...

  8. redis数据导入与导出以及配置使用

    最近在研究redis 遇到redis requires Ruby version >= 2.2.2问题 解决办法是 先安装rvm,再把ruby版本提升至2.3.3 1.安装curl sudo y ...

  9. 059、Java中定义一个有参数无返回值的方法

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  10. 017、Java中使用float型

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...