Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)
题目链接 The Meeting Place Cannot Be Changed
二分答案即可。
check的时候先算出每个点可到达的范围的区间,然后求并集。判断一下是否满足l <= r就好了。
eps我设了1e-7。
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i(a); i <= (b); ++i) const int N = + ;
const double eps = 1e-; double mi, ma; struct node{
double x, y;
friend bool operator < (const node &a, const node &b){
return a.x < b.x;
}
}a[N];
int n; double c[N], d[N]; bool check(double x){
rep(i, , n){
c[i] = a[i].x - a[i].y * x;
d[i] = a[i].x + a[i].y * x;
} double l = c[], r = d[];
rep(i, , n){
l = max(l, c[i]);
r = min(r, d[i]);
} return l <= r;
} int main(){ mi = 2e9, ma = -mi;
scanf("%d", &n);
rep(i, , n){
scanf("%lf", &a[i].x);
mi = min(mi, a[i].x);
ma = max(ma, a[i].x);
} rep(i, , n){
scanf("%lf", &a[i].y);
} sort(a + , a + n + ); double l = , r = ;
while (abs(l - r) > eps){ double mid = (l + r) / ; if (check(mid)) r = mid; else l = mid;
} printf("%.10f\n", l);
return ; }
Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)的更多相关文章
- CodeForces 782B The Meeting Place Cannot Be Changed (二分)
题意:题意:给出n个人的在x轴的位置和最大速度,求n个人相遇的最短时间. 析:二分时间,然后求并集,注意精度,不然会超时. 代码如下: #pragma comment(linker, "/S ...
- 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 ...
- codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)
B. The Meeting Place Cannot Be Change ...
- Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)
The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...
- 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 ...
- CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)
题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间. 分析: 1.二分枚举最短时间即可. 2.通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜 ...
- 782B. The Meeting Place Cannot Be Changed 二分 水
Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...
- 782B The Meeting Place Cannot Be Changed(二分)
链接:http://codeforces.com/problemset/problem/782/B 题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...
- Codeforces Round #352 (Div. 2) D. Robin Hood (二分答案)
题目链接:http://codeforces.com/contest/672/problem/D 有n个人,k个操作,每个人有a[i]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差 ...
随机推荐
- 图论:HDU2544-最短路(最全、最经典的最短路入门及小结)
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- Tricky Sum
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all po ...
- Session只读的影响
.net中使用Session必须实现IRequiresSessionState接口,不过还有个只读的接口IReadOnlySessionState, 若是实现只读的接口,那么在该页面(如一般处理程序) ...
- spark测试几个hadoop的典型例子
1.求每年的最高温度数据格式如下: 0067011990999991950051507004888888889999999N9+00001+999999999999999999999900670119 ...
- 《鸟哥的Linux私房菜》学习笔记(7)——grep及正则表达式
一.grep命令 grep:根据模式搜索文本,并将符合模式的文本行显示出来 模式:由文本字符和正则表达式的元字符组合成的匹配条件 命令格式:grep [options] [file...] [root ...
- Android ListView用法
写了一个简单的示例来说明ListView的用法:给定一个单词,下面有四个含义,找出正确的一个,无论是否成功,则会跳转到下一个单词:主要用到的知识有: findViewById(). ListView ...
- [oldboy-django][2深入django]rest-framework教程
# rest-framework教程 - settings.py INSTALL-APPS = [ 'snippets', # app 'rest-framework', ] - 创建model # ...
- redis linux 安装
安装 1): wget http://download.redis.io/releases/redis-5.0.2.tar.gz 2): tar xzf redis-5.0.2.tar.gz 3):c ...
- activemq 简单聊天
有兴趣加群qq:200634530
- MySQL误操作后如何快速恢复数据?
摘要: 利用binlog闪回误操作数据. 基本上每个跟数据库打交道的程序员(当然也可能是你同事)都会碰一个问题,MySQL误操作后如何快速回滚?比如,delete一张表,忘加限制条件,整张表没了.假如 ...