CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)
题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间。
分析:
1、二分枚举最短时间即可。
2、通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜索范围。
3、相当于二分枚举找右临界线,符合要求的点都在右边。
4、通过给二分一个查找次数的上界,eg:k=200,而不是dcmp(l, r)<=0,后者会tle。
5、检查是否有交集,就是以第一个点的最大移动区间为标准,不断与其他区间取交集并更新再继续比较。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 60000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int a[MAXN], v[MAXN];
int n;
bool judge(double t){
double tmpl = (double)a[0] - (double)v[0] * t;
double tmpr = (double)a[0] + (double)v[0] * t;
for(int i = 1; i < n; ++i){
double l = (double)a[i] - (double)v[i] * t;
double r = (double)a[i] + (double)v[i] * t;
if(dcmp(tmpl, r) > 0 || dcmp(tmpr, l) < 0) return false;
if(dcmp(l, tmpl) > 0) tmpl = l;
if(dcmp(r, tmpr) < 0) tmpr = r;
}
return true;
}
double solve(){
double l = 0, r = (double)1e9;
int k = 200;
while(k--){
double mid = (l + r) / 2;
if(judge(mid)) r = mid;
else l = mid + eps;
}
return r;
}
int main(){;
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
for(int i = 0; i < n; ++i){
scanf("%d", &v[i]);
}
printf("%.12lf\n", solve());
return 0;
}
CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)的更多相关文章
- 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(二分答案)
题目链接 The Meeting Place Cannot Be Changed 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...
- codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)
B. The Meeting Place Cannot Be Change ...
- 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个人的在x轴的位置和最大速度,求n个人相遇的最短时间. 析:二分时间,然后求并集,注意精度,不然会超时. 代码如下: #pragma comment(linker, "/S ...
- 782B The Meeting Place Cannot Be Changed(二分)
链接:http://codeforces.com/problemset/problem/782/B 题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...
- 782B. The Meeting Place Cannot Be Changed 二分 水
Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...
- 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 ...
- AC日记——The Meeting Place Cannot Be Changed codeforces 780b
780B - The Meeting Place Cannot Be Changed 思路: 二分答案: 代码: #include <cstdio> #include <cstrin ...
随机推荐
- Kubernetes——机密数据管理
k8s——机密数据管理1.secret2.configMap kubectl explain secret #查看帮助手册然后将你要加密的变量值做些许处理:echo 123 | base64 ...
- Vue二次精度随笔(1)
1.button.input标签的disabled属性 该标签可以控制按钮是否可用,如果他的值为以上几种的话,则他都不会在标签上渲染出这个属性,一旦这个属性出现的话,就说明他是禁用的 2.移除动态绑定 ...
- Linux centosVMware 磁盘格式化、磁盘挂载、手动增加swap空间
一.磁盘格式化 磁盘分区后不能直接使用,需要对每一个分区格式化,格式化其实就是安装系统文件. 命令mke2fs:不支持格式化成xfs系统文件 mkfs.ext4 == mke2fs -t ext4 ...
- linux环境下安装solr
1.上传并解压solr文件 2.将solr解压缩包的dist/solr-4.10.3.war包部署到tomcat下.并改名为solr.war 3.解压war包(启动tomcat后会自动解压war包) ...
- 「USACO08JAN」电话线Telephone Lines
传送门 Luogu 解题思路 考虑二分,每次把大于二分值的边的权设为1,小于等于的设为0,如果最短路<=k则可行,记得判无解 细节注意事项 咕咕咕 参考代码 #include <algor ...
- Html5使用audio播放音乐
html代码 <audio id="myaudio" src="http://ws.stream.qqmusic.qq.com/C100003R74Cn0JR4O ...
- python内置函数三
ord() 函数 和 chr() 相反 chr() 是将数字转换成assci码 ord() 是将字符串转换成assci码 显示 pow() 函数 pow(x,y,z) 表示x**y ...
- python表白实现代码(可视化与动画版)
python表白实现代码(可视化与动画版)如何优雅而又高大上地对自己的心爱女神表白了? ? ? 试试python表白的实现方式吧,是动画版的哦,保证可以如你所愿 ! ! !最终的实现效果如下: 具体实 ...
- VMware导入和删除虚拟机文件
VMware中导入已存在的虚拟机文件: 1.文件-->打开-->选择虚拟机文件-->完成 VMware中完全删除虚拟机文件 2.在虚拟机上右键单击-->管理--> ...
- 在web.xml中可以设置jsp标签吗?
<jsp-config> <taglib> <taglib-uri>http://java.sun.com/jstl/core</taglib-uri> ...