Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
地址:http://codeforces.com/contest/782/problem/B
题目:
5 seconds
256 megabytes
standard input
standard output
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
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
思路:二分时间:判断所有点的可到区间求交是否非空;
或三分位置:位置是倒过来的单峰函数。
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e5+;
const int mod=1e9+; int n,ff;
double v[K],pos[K];
double l,r,x,y,mid; bool check(double t)
{
x=0.0,y=1e9;
for(int i=;i<=n;i++)
{
x=max(x,pos[i]-t*v[i]);
y=min(y,pos[i]+t*v[i]);
}
return y>=x||abs(y-x)<eps;
}
int main(void)
{
cin>>n;
for(int i=;i<=n;i++)
cin>>pos[i];
for(int i=;i<=n;i++)
cin>>v[i];
l=0.0,r=1e9;
for(int i=;i<=;i++)
{
mid=(r+l)/2.0;
if(check(mid)) r=mid;
else l=mid;
}
printf("%.6f\n",(r+l)/2.0);
return ;
}
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed的更多相关文章
- 【三分】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed
三分显然,要注意EPS必须设成1e-6,设得再小一点都会TLE……坑炸了 #include<cstdio> #include<algorithm> #include<cm ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A模拟 B三分 C dfs D map
A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League
地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...
- 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E
http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...
- 2-sat Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D
http://codeforces.com/contest/782/problem/D 题意: 每个队有两种队名,问有没有满足以下两个条件的命名方法: ①任意两个队的名字不相同. ②若某个队 A 选用 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E Underground Lab
地址:http://codeforces.com/contest/782/problem/E 题目: E. Underground Lab time limit per test 1 second m ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons
地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A. Andryusha and Socks
地址:http://codeforces.com/contest/782/problem/A 题目: A. Andryusha and Socks time limit per test 2 seco ...
随机推荐
- hdu 4685(匹配+强连通分量)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4685 思路:想了好久,终于想明白了,懒得写了,直接copy大牛的思路了,写的非常好! 做法是先求一次最 ...
- D3D中的渲染状态简介
1). 设置着色模式: SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT) //设置平面着色模式 SetRenderState(D3DRS_SHADEMODE ...
- [黑金原创教程] FPGA那些事儿《设计篇 I》- 图像处理前夕
简介 一本为入门图像处理的入门书,另外还教你徒手搭建平台(片上系统),内容请看目录. 注意 为了达到最好的实验的结果,请准备以下硬件. AX301开发板, OV7670摄像模块, VGA接口显示器, ...
- 【BZOJ3809/3236】Gty的二逼妹子序列 [Ahoi2013]作业 莫队算法+分块
[BZOJ3809]Gty的二逼妹子序列 Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b ...
- ios UITableView高度自适应(转)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { // ...
- spring-boot 打包成 war包发布
1.用maven打包成war包 2.将war包用zip方式打开,删除里面的tomcat-embed相关的4个包,删除spring-boot-tomcat包 3.将删除了tomcat相关嵌入包后的war ...
- Maven聚合、Maven仓库jar包以及Spring+MyBatis+JUnit+Maven整合测试的搭建过程
一.Maven将父项目创建到父项目的内部 在父项目的pom.xml上 点右键,选择maven-->new-->maven module project 二.Maven聚合 在某个项目的p ...
- JavaScript面向对象OOP思想Class系统
JavaScript的Class模块,纯天然无依赖,只有2k大小,快速高效,让我们优雅的面向对象... | |目录 1源码:jClass.js 2源码:jClass.min.js 3构建一个类 4访问 ...
- R中K-Means、Clara、C-Means三种聚类的评估
R中cluster中包含多种聚类算法,下面通过某个数据集,进行三种聚类算法的评估 # ============================ # 评估聚类 # # ================= ...
- file结构中的private_data
private_data是Linux下连接VFS文件系统框架和不同文件/文件系统底层实现之间的一个核心数据结构,虽然它只是一个指针,但是一个指针可以解决所有问题. 因 为file是VFS框架的一个基本 ...