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. Python:Python的运行过程

    1.Python是什么 和Java以及c#一样,Python也是一门基于虚拟机的语言.熟悉Java开发的人在命令行执行一个Java程序的过程通常如下: javac hello.java java he ...

  2. 第四次c++作业

    一,GitHub地址 https://github.com/ronghuijun/3Elevators-scheduling 二,命令行和文件读写 百度有时候有点蒙,命令行用的是D:>Eleva ...

  3. HDU 5225 枚举

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5225 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  4. web.config详解(转载)

    该文为转载 原文地址:http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html 花了点时间整理了一下ASP.NET Web.c ...

  5. 第112天:javascript中函数预解析和执行阶段

    关于javascript中的函数:  1.预解析:把所有的函数定义提前,所有的变量声明提前,变量的赋值不提前  2.执行 :从上到下执行,但有例外(setTimeout,setInterval,aja ...

  6. 第84天:jQuery动态创建表格

    jQuery动态创建表格 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  7. 【ASP.NET Core】ASP.NET Core 依赖注入

    一.什么是依赖注入(Denpendency Injection) 这也是个老身常谈的问题,到底依赖注入是什么? 为什么要用它? 初学者特别容易对控制反转IOC(Iversion of Control) ...

  8. 前端开发学习之——利用模板实现涉及url问题时的bug分析及解决(chrome源码)

    例如我们要实现如下页面,其中历史页面列表想来自底层返回的数据,此处用testData代替: 最初我写的实现代码如下: html文件: <!doctype html> <html cl ...

  9. C++之高级编程20170914

    /*************************************************************************************************** ...

  10. js中字符串全部替换

    废话不多说,直接发结果 在js中字符串全部替换可以用以下方法: str.replace(/需要替换的字符串/g,"新字符串") 比如: "yyyy-MM-dd-hh-mm ...