【codeforces 782B】The Meeting Place Cannot Be Changed
【题目链接】:http://codeforces.com/contest/782/problem/B
【题意】
每个人都有一个速度,只能往上走或往下走;
然后让你找一个地方,所有人都能够在t时间内到达;
让t最小.
【题解】
很明显的二分了;
二分时间t;
对于某个时间t,这个人都有一个能够到达的唯一区间
[x[i]-v*t..x[i]+v*t]
如果所有人的区间都有交集.
那么就能在那些交集里面随便选一个点了;
区间的交集可以用
最大的左端点小于等于最小的右端点这个依据来判断是否存在
想让答案的精度高一点,就让程序的二分多做几次就好;
固定200次就够了
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 6e4+100;
int x[N], v[N];
int n;
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n);
rep1(i, 1, n)
rei(x[i]);
rep1(i, 1, n)
rei(v[i]);
double l = 0, r = 1e9 + 100,ans = 0;
rep1(j,1,200)
{
double m = (l + r) / 2;
double ll = -1e18, rr = 1e18;
rep1(i, 1, n)
{
double t1 = x[i] - m*v[i], t2 = x[i] + m*v[i];
ll = max(ll, t1), rr = min(rr, t2);
}
if (ll <= rr)
{
ans = m;
r = m;
}
else
l = m;
}
printf("%.12lf\n", ans);
return 0;
}
【codeforces 782B】The Meeting Place Cannot Be Changed的更多相关文章
- Codeforces 782B:The Meeting Place Cannot Be Changed(三分搜索)
http://codeforces.com/contest/782/problem/B 题意:有n个人,每个人有一个位置和速度,现在要让这n个人都走到同一个位置,问最少需要的时间是多少. 思路:看上去 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【55.70%】【codeforces 557A】Ilya and Diplomas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- 知无涯者(The Man Who Knew Infinity)
1913年的1月16号在剑桥大学的三一学院那里,著名的数学家哈代教授收到了一封信,信的开头是这种: "尊敬的先生.仅自我介绍例如以下,我是马德拉斯港务信托处的一个职员,年薪唯独20英镑.23 ...
- python opencv —— io(帧、图像、视频的读取与保存)
0. VideoCapture VideoCapture:构造函数: 常见成员函数: open:打开视频文件,或者捕获视频设备,该函数会首先调用 release() 函数以关闭已打开的文件或设备: P ...
- RMQ问题-ST方法
参考 http://blog.csdn.net/sdj222555/article/details/7875575 RMQ 就是 Range Minimum/Maximum Query 就是求区间最值 ...
- [React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber
Using a react-intl FormattedNumber component, we'll pass a Number and a few additional props in orde ...
- Oracle游标进行循环效率比较
对300万一张表数据,用游标进行循环,不同写法的效率比较 对300万一张表数据,用游标进行循环,不同写法的效率比较 1.显示游标 declare cursor cur_2 is sel ...
- orabbix 报错No suitable driver found for
orabbix报错如下: 2018-07-11 14:35:20,119 [main] ERROR Orabbix - Error on Configurator for database qa ...
- Android5.0(Lollipop) BLE蓝牙4.0+浅析demo连接(三)
作者:Bgwan链接:https://zhuanlan.zhihu.com/p/23363591来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. Android5.0(L ...
- vue学习笔记三:常见的表单绑定
<template> <div id="app"> <input type="checkbox" id="checked ...
- [慕课笔记]mongodb入门篇
一:对mongodb有一个系统的完备的了解,只有概念清楚了,才能更好的使用 二:学会mongodb数据库的搭建 首先:了解如何部署数据库的服务 搭建简单的单机服务到搭建具有冗余容错功能的复制集再到搭建 ...
- Satisfying memory ordering requirements between partial reads and non-snoop accesses
A method and apparatus for preserving memory ordering in a cache coherent link based interconnect in ...