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. C++:构造函数1——普通构造函数

    前言:构造函数是C+中很重要的一个概念,这里对其知识进行一个简单的总结 一.构造函数的定义 1.类中的构造函数名与类名必须相同 2.构造函数没有函数的返回类值型说明符 [特别注意]: a.构造函数的返 ...

  2. Markdown的基本语法

    Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown 的语法十分简单.常用的标记符号也不 ...

  3. C++对象模型 多重继承与虚函数表

    一 多重继承 1) 代码: Code#include <iostream>using namespace std; class B1{public:    int x;    virtua ...

  4. ci事务

    CI框架百问百答:CodeIgniter的事务用法?--第9问 时间 2013-06-06 10:57:45  CSDN博客 原文  http://blog.csdn.net/haor2756/art ...

  5. 【vue】父组件主动调用子组件 /// 非父子组件传值

    一  父组件主动调用子组件: 注意:在父组件使用子组件的标签上注入ref属性,例如: <div id="home"> <v-header ref="he ...

  6. python/django将mysql查询结果转换为字典组

    使用python查询mysql数据库的时候,默认查询结果没有返回表字段名称,不方便使用.为了方便使用一般会选择将查询结果加上字段名称以字典组的方式返回查询结果. 实现如下: def dict_fetc ...

  7. Ubuntu 16.04 LTS安装sogou输入法详解

    http://blog.csdn.net/qq_21792169/article/details/53152700 最近开始学习linux 在安装输入法中遇到的一些问题,最终成功安装,也得益于网络上的 ...

  8. solr服务器的查询过程

    SolrDispatchFilter的作用 This filter looks at the incoming URL maps them to handlers defined in solrcon ...

  9. 【bzoj3774】最优选择 网络流最小割

    题目描述 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bij ...

  10. 【bzoj2906】颜色 分块

    题目描述 给定一个长度为N的颜色序列C,对于该序列中的任意一个元素Ci,都有1<=Ci<=M.对于一种颜色ColorK来说,区间[L,R]内的权值定义为这种颜色在该区间中出现的次数的平方, ...