题意:题意:给出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. hdu2188 Check Corners

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. spark 单机版安装

    jdk-8u73-linux-x64.tar.gz hadoop-2.6.0.tar.gz scala-2.10.6.tgz spark-1.6.0-bin-hadoop2.6.tgz 1.安装jdk ...

  3. BZOJ1999 树网的核[数据加强版]

    1999: [Noip2007]Core树网的核 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1214  Solved: 336[Submit][St ...

  4. Proxmox qm命令应用实例

          1) 把一个物理硬盘增加到VM上qm set 105 --virtio1 /dev/sdb     <-- 表示把/dev/sdb物理硬盘以 virtio 接口类型增加至 105 的 ...

  5. commandLink/commandButton/ajax backing bean action/listener method not invoked (转)

    Whenever an UICommand component fails to invoke the associated action method or an UIInputelement fa ...

  6. Doubango开源项目

    compv Insanely fast computer vision library for ARM and x86 devices (Up to #50 times faster than Ope ...

  7. String是基本的数据类型吗?

    String不是基本的数据类型,是final修饰的java类,java中的基本类型一共有8个,它们分别为: 1 字符类型:byte,char 2 基本整型:short,int,long 3 浮点型:f ...

  8. docker 端口映射iptables: No chain/target/match by that name错误解决方法

    pkill docker iptables -t nat -F ifconfig docker0 down brctl delbr docker0 service docker restart

  9. 基于RFC5321使用ncat发送邮件

    今天和同事学习到的这个方法,学习了,记录一下: [root@localhost ~]# ncat TeamServer.localdomain ESMTP Postfix EHLO l00.win - ...

  10. 使用cython把python编译so

    1.需求 为了保证线上代码安全和效率,使用python编写代码,pyc可直接反编译,于是把重要代码编译so文件 2.工作 2.1 安装相关库: pip install cython yum insta ...