CF782B The Meeting Place Cannot Be Changed
题意:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are n friends, and i-th of them is standing at the point xi meters and can move with any speed no greater than vi meters per second in any of the two directions along the road: south or north.
You are to compute the minimum time needed to gather all the n friends at some point on the road. Note that the point they meet at doesn't need to have integer coordinate.
The first line contains single integer n (2 ≤ n ≤ 60 000) — the number of friends.
The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) — the current coordinates of the friends, in meters.
The third line contains n integers v1, v2, ..., vn (1 ≤ vi ≤ 109) — the maximum speeds of the friends, in meters per second.
Print the minimum time (in seconds) needed for all the n friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10 -6. Formally, let your answer be a, while jury's answer be b. Your answer will be considered correct if holds.
3
7 1 3
1 2 1
2.000000000000
4
5 10 3 2
2 3 2 4
1.400000000000
思路:
二分,注意控制精度。
实现:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
struct node
{
double pos;
double speed;
};
node a[];
int n;
double minn, maxn;
bool check(double t)
{
minn = a[].pos - t * a[].speed;
maxn = a[].pos + t * a[].speed;
for (int i = ; i < n; i++)
{
double tmp_l = a[i].pos - t * a[i].speed;
double tmp_r = a[i].pos + t * a[i].speed;
minn = max(minn, tmp_l);
maxn = min(maxn, tmp_r);
}
return maxn - minn >= 1e-;
} double solve()
{
double l = 0.0, r = , res = ;
for (int i = ; i < ; i++)
{
double mid = (l + r) / 2.0;
if (check(mid))
{
r = mid;
res = mid;
}
else
{
l = mid;
}
}
return res;
} int main()
{
cin >> n;
for (int i = ; i < n; i++)
{
cin >> a[i].pos;
}
for (int i = ; i < n; i++)
{
cin >> a[i].speed;
}
cout << setprecision() << solve() << endl;
return ;
}
CF782B 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 ...
- code force 403B.B. The Meeting Place Cannot Be Changed
B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...
- Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)
The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...
- 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 ...
- 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 ...
- CodeForce-782B The Meeting Place Cannot Be Changed(高精度二分)
https://vjudge.net/problem/CodeForces-782B B. The Meeting Place Cannot Be Changed time limit per tes ...
- B. The Meeting Place Cannot Be Changed
B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...
随机推荐
- 如何使用git 生成patch 和打入patch【转】
本文转载自:http://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用 ...
- HDU1532 Drainage Ditches —— 最大流(sap算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/ ...
- 自定义表单SQL命令行批量删除垃圾留言
1.每天被恶意留言困扰,花费大量的时间去清理却效果不理想,对于没有能力做二次开发并且靠纯手工删除留言的菜鸟来讲是一个大麻烦. 2.大家都知道织梦的留言内容是存在数据库里的,而数据库的内容是可以批量删除 ...
- [laravel]phpunit
step1.install phpunit composer.json require中增加 "phpunit/phpunit":"4.0.*" 执行 comp ...
- [yii2]Module的Namespace和控制器位置
namespace和目录对应,否则无法找到控制器类,module文件在根路径 使用gii生成Module为\app\admin,那么 namespace app; class admin extend ...
- [TJOI2012]防御
https://www.zybuluo.com/ysner/note/1332539 题面 戳我 解析 一道挺棒棒的线段树. 显然一次伤害到来时我们要先看看区间内哪些点的护甲没了. 这个可以通过维护区 ...
- Button Style
Button Style BS_3STATE 与复选框一样本样式按钮可被单击变暗.变暗状态通常用于指示本样式的按键正处于禁用状态. BS_AUTO3STATE 与三状态的复选框一样当用户选中它本按钮样 ...
- View Controller Programming Guide for iOS---(七)---Resizing the View Controller’s Views
Resizing the View Controller’s Views A view controller owns its own view and manages the view’s cont ...
- NYOJ7——街区最短路径问题
街区最短路径问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述:一个街区有很多住户,街区的街道只能为东西.南北两种方向.住户只可以沿着街道行走.各个街道之间的间隔相等 ...
- E20170403-gg
thumbnail 缩略图 inherit vt. 继承; vt. 经遗传获得(品质.身体特征等),继任; opacity 不透明度 flat adj. 平的; 单调的; 不景气的 ...