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]个物品,每次操作把最富的人那里拿一个物品给最穷的人,问你最后贫富差 ...
随机推荐
- datatime来计算代码段运行时长
小知识点:编程中一般都是先乘后除,这样结果更为精确 先定义 DataTime startTime = DataTime.Now; 中间是运行代码 最后TimeSpan ts = DataTime.No ...
- 浅谈I/O模型
在学习线程,NIO等知识时都需要知道一些基础知识. 一.什么是同步或异步 同步:个人通俗理解多个人排队打饭一个窗口,只有前面一个人打完了,后面的人才能打.如果前面人因为什么原因一直站在那里不走,后面的 ...
- 利用js阻止表单提交
(1) return false <form name="loginForm" action="login.aspx" method="post ...
- java作业8
interface Pet{ public String getName(); public String getColor(); public int getAge(); } class Cat i ...
- Zookeeper 增删改查
初始化对象连接到zookeeper服务: public ZooKeeper initZk(){ final CountDownLatch countDownLatch = new CountDownL ...
- 翻译MDN里js的一些方法属性
TypeError The TypeError object represents an error when a value is not of the expected type. [TypeEr ...
- 服务器(centos7)用nginx挂出多个网站的配置
前提: 装好环境的centos7系统(其他版本也行),装好ngnix: 推荐:http://www.cnblogs.com/alsy/p/5296244.html 把你的项目上传到服务器上(可以用Xf ...
- MyEclipse断点调试方法
MyEclipse断点调试方法 最基本的操作是: 1, 首先在一个java文件中设断点,然后运行,当程序走到断点处就会转到debug视图下, 2, F5键与F6键均为单步调试,F5是step into ...
- 【转】unity自带寻路Navmesh入门教程(三)
http://liweizhaolili.blog.163.com/blog/static/16230744201271225812998/ 继续介绍NavMesh寻路的功能,接下来阿赵打算讲一下以下 ...
- 【转】ugui自制摇杆
http://www.cnblogs.com/duyushuang/p/4457691.html 珍爱生命,远离插件. 以上8个字,好好理解. 反正我是这么觉得. 我说的是unity,不是魔兽世界. ...