题意:题意:给出n个人的在x轴的位置和最大速度,求n个人相遇的最短时间。

析:二分时间,然后求并集,注意精度,不然会超时。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-7;
const int maxn = 60000 + 5;
const int mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} struct Node{
double x, v;
};
Node a[maxn]; bool judge(double m){
double l = a[0].x-a[0].v*m, r = a[0].x+a[0].v*m;
for(int i = 1; i < n; ++i){
l = max(l, a[i].x-a[i].v*m);
r = min(r, a[i].x+a[i].v*m);
if(r < l) return false;
}
return r >= l;
} int main(){
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%lf", &a[i].x);
}
for(int i = 0; i < n; ++i){
scanf("%lf", &a[i].v);
}
double l = 0.0, r = 1e9;
while(r - l > eps){
double m = (l + r) / 2.0;
if(judge(m)) r = m;
else l = m;
}
printf("%.6f\n", l);
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 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...

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

  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个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间. 分析: 1.二分枚举最短时间即可. 2.通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜 ...

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

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

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

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

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

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

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

随机推荐

  1. 前端调错看ajax请求操作

    ---------------------------------------------------------------------------------------------------- ...

  2. rpy2的安装问题?【解决】

    https://www.zhihu.com/question/46555829 http://blog.sciencenet.cn/blog-365459-901335.html

  3. 洛谷 P1655 小朋友的球

    题目描述 @发源于 小朋友最近特别喜欢球.有一天他脑子抽了,从口袋里拿出了N个不同的球,想把它们放到M个相同的盒子里,并且要求每个盒子中至少要有一个球,他好奇有几种放法,于是尝试编程实现,但由于他天天 ...

  4. angularJs 指令的封装

    首先 指令的应用场景: 1:使你的html更具语义化,不需要深入研究代码就可以知道页面的大概逻辑. 2:抽象出一个自定义组件,在其他的地方进行重用. 一:directive的定义及其使用方法: 下面是 ...

  5. loj 6485 LJJ学二项式定理 —— 单位根反演

    题目:https://loj.ac/problem/6485 先把 \( a_{i mod 4} \) 处理掉,其实就是 \( \sum\limits_{i=0}^{3} a_{i} \sum\lim ...

  6. Azure CLI的Query

    Azure CLI 2.0是基于Python的命令行.其命令直观,使用非常方便. 其输出有四种模式: --output -o : Output format. Allowed values: json ...

  7. 配置文件的继承与覆盖: Machine.config / Web.config /子目录 Web.config

    C#有三种级别的配置文件: 机器级别 machine.config 在 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.c ...

  8. GWT嵌入纯HTML页面

    众所周知,gwt页面是java代码所写,不存在html页面直接作用于gwt面板中.不过gwt也倒是提供了一些可用的功能,比如frame,这个是UI中的一个,内部可以设置URL,但是经过我测试后发现,这 ...

  9. RDD之一:总体介绍

    摘要 本文提出了分布式内存抽象的概念——弹性分布式数据集(RDD,Resilient Distributed Datasets),它具备像MapReduce等数据流模型的容错特性,并且允许开发人员在大 ...

  10. oralce 记一次 External Procedure initial connection 处理

    1 环境 oracle 11.2.0.4 RAC(2 nodes),centos 6.8,实体机 2 问题 线上环境执行一条sql sql> select ST_AsText(ST_Geomet ...