题意:在一维坐标轴上,给定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. axios设置请求头失效的问题

    前言:因为在使用vue-element-admin框架时遇到了设置请求头失效的问题,在后来发现是代理跨域问题,所以又简单理解了一下跨域. 出现的问题是我在axios拦截器上设置了请求头token,但是 ...

  2. Day3-P - Matrix POJ3685

    Given a N × N matrix A, whose element in the i-th row and j-th column Aij is an number that equals i ...

  3. LATTICE 编程烧录器HW-USBN-2B使用说明

    HW-USBN-2B说明文档 1.       引脚定义 编程引脚 名称 编程设备引脚类型 描述 VCC 编程电压 输入 连接VCC到目标设备,典型的ICC=10Ma.板子设计必须考虑VCC的电流供应 ...

  4. Unbutu下装oracle

    Ubuntu 16.04安装Oracle 11gR2入门教程图文详解 转自         https://www.linuxidc.com/Linux/2017-12/149797.htm  原文作 ...

  5. loadBeanDefinitions方法源码跟踪(三)

    因为字数超过了限制,所以分成了三篇,承接上篇: https://www.jianshu.com/p/46e27afd7d96 代码过宽,可以shift + 鼠标滚轮 左右滑动查看 4.parseCus ...

  6. Element-UI Table 实现筛选数据功能

    最近产品提出了一个筛选数据的功能,要求在表头里实现一个下拉框进行筛选. 首先, Element-ui 的官方文档,el-table-column 下有一个 filters , 用于数据的筛选和过滤, ...

  7. 用 Python 编写一个天气查询应用

    效果预览: 一.获取天气信息 使用python获取天气有两种方式. 1)是通过爬虫的方式获取天气预报网站的HTML页面,然后使用xpath或者bs4解析HTML界面的内容. 2)另一种方式是根据天气预 ...

  8. fastutil优化数据结构使用示例

    fastutil githup 链接 pom.xml文件引入依赖 <dependency> <groupId>fastutil</groupId> <arti ...

  9. leetcode1019 Next Greater Node In Linked List

    """ We are given a linked list with head as the first node. Let's number the nodes in ...

  10. springmv返回JSON数据格式

    1.先导入依赖 <!-- springmvc使用@responseBody start--> <dependency> <groupId>com.fasterxml ...