Link

题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少。

思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所花时间,缩小范围即可。

/** @Date    : 2017-05-09 22:07:43
* @FileName: 782B.cpp
* @Platform: Windows
* @Author : Lweleth (SoundEarlf@gmail.com)
* @Link : https://github.com/Lweleth
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-6; double p[60010];
double v[60010];
double tim;
int n;
int check(double x)
{
double lt = 0, rt = 0;
for(int i = 0; i < n; i++)
{
if(p[i] < x)
lt = max(lt, (x - p[i]) / v[i]);
else if(p[i] > x)
rt = max(rt, (p[i] - x) / v[i]);
}
tim = max(lt, rt);
return (lt >= rt);
} int main()
{
while(cin >> n)
{
double ma = 0;
for(int i = 0; i < n; i++) scanf("%lf", p + i), ma = max(ma, p[i]);
for(int i = 0; i < n; i++) scanf("%lf", v + i); double l = 0, r = ma;
while(r - l >= eps)
{
double mid = (r + l) / 2.0000;
if(check(mid))
r = mid;
else
l = mid;
//cout << mid << endl;
}
printf("%.10lf\n", tim);
}
return 0;
}

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 (二分)

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

  3. Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)

    The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...

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

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

                                                                   B. The Meeting Place Cannot Be Change ...

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

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

  7. CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)

    题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间. 分析: 1.二分枚举最短时间即可. 2.通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜 ...

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

  9. CodeForce-782B The Meeting Place Cannot Be Changed(高精度二分)

    https://vjudge.net/problem/CodeForces-782B B. The Meeting Place Cannot Be Changed time limit per tes ...

随机推荐

  1. 各团队对《t铁大导航》评价及我组回复

    组名 对我们组的建议 我组回复 (1)跑男 你们的导航前期要做到什么样的程度呢?其实我一直是很期待你们完成时我能够用你们的导航来感受一下咱们铁大校园风情.你们用了数据结构算法来找最短路径,那你们能不能 ...

  2. [转]精选!15个必备的VSCode插件

    Visual Studio Code 是由微软开发的一款免费.跨平台的文本编辑器.由于其卓越的性能和丰富的功能,它很快就受到了大家的喜爱. 就像大多数 IDE 一样,VSCode 也有一个扩展和主题市 ...

  3. Alpha冲刺——第九天

    Alpha第九天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...

  4. 用vs调试项目的时候报HTTP 错误 403.14 - Forbidden

    曾经遇到过这种诡异的问题,你一定想不到,这个可能是因为你用svn合并的时候,导致了你的dll文件出了问题. 竟然可以用主干的dll替换的方式,解决掉这个问题.

  5. lintcode-433-岛屿的个数

    433-岛屿的个数 给一个01矩阵,求不同的岛屿的个数. 0代表海,1代表岛,如果两个1相邻,那么这两个1属于同一个岛.我们只考虑上下左右为相邻. 样例 在矩阵: [ [1, 1, 0, 0, 0], ...

  6. jQuery之过滤元素

    还是那句话,这些知识一个小小的练习,更多的请看jQuery手册 在jQuery对象中的元素对象数组中过滤出一部分元素来1. first()2. last()3. eq(index|-index)4. ...

  7. CentOS yum 安装LAMP PHP5.4版本

    CentOS yum 安装LAMP PHP5.4版本 [日期:2015-06-04] 来源:Linux社区  作者:rogerzhanglijie [字体:大 中 小]     Linux系统版本:C ...

  8. sysbench 环境安装,压测mysql

    源码路径:https://github.com/akopytov/sysbench 版本linux 6.8sysbench 0.5mysql 5.6.29 1.安装pip略 2.pip 安装bzr p ...

  9. PHP中普通方法和静态方法

    普通方法(实例方法) 一个类中定义的方法,可以为这个类的所有对象调用的方法.也可以理解为,这个类的所有对象,都各自有自己的一个该方法: 定义形式: class  类名{ function  方法名(形 ...

  10. 【经典数据结构】Trie

    在计算机科学中,trie,又称前缀树或字典树,是一种有种树,用于保存关联数组,其中的键通常是字符串.与二叉查找树不同,键不是直接保存在节点中,而是由节点在树中的位置决定.一个节点的所有子孙都有相同的前 ...