B. The Meeting Place Cannot Be Changed
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.
思路:二分;
二分时间,然后每次检查时求出每个点所能到达的左右的距离,然后求线段的最大重叠。复杂度(n*log^2(n))
或者二分每次检查时求出每个点所能到达的左右的距离,然后维护最小的右端r,和最大的左端l,如果r > l成立复杂度n*log(n);
1 #pragma comment(linker, "/STACK:102400000,102400000")
2 #include<stdio.h>
3 #include<algorithm>
4 #include<iostream>
5 #include<string.h>
6 #include<stdlib.h>
7 #include<queue>
8 #include<map>
9 #include<math.h>
10 #include<vector>
11 const int N = 1e6+6;
12 using namespace std;
13 typedef long long LL;
14 double x[70000];
15 double v[70000];
16 typedef struct node
17 {
18 double val;
19 int k;
20 } ss;
21 bool cmp(node p,node q)
22 {
23 if(p.val == q.val)
24 return p.k > q.k;
25 else return p.val < q.val;
26 }
27 ss ask[70000*2];
28 bool check(double c,int n);
29 int main(void)
30 {
31 int n;
32 scanf("%d",&n);
33 for(int i = 1; i <= n; i++)
34 scanf("%lf",&x[i]);
35 for(int i = 1; i <= n; i++)
36 scanf("%lf",&v[i]);
37 int t = 100;
38 double ll = 0,rr = 1e10;
39 double acc = -1;
40 while(t)
41 {
42 double mid = (ll+rr)/2;
43 if(check(mid,n))
44 {
45 acc = mid;
46 rr = mid;
47 //printf("%lf\n",mid);
48 }
49 else ll = mid;
50 t--;
51 }
52 printf("%.10f\n",acc);
53 return 0;
54 }
55 bool check(double c,int n)
56 {
57 int cn = 0;
58 for(int i = 1; i <= n; i++)
59 {
60 ask[cn].val = max((double)0,x[i] - c*v[i]);
61 ask[cn].k = 1;
62 cn++;
63 ask[cn].val = x[i] + c*v[i];
64 ask[cn].k = -1;
65 cn++;
66 }
67 int sum = 0;
68 sort(ask,ask+cn,cmp);
69 for(int i = 0; i < cn; i++)
70 {
71 sum += ask[i].k;
72 if(sum == n)
73 return true;
74 }
75 return false;
76 }
1 #pragma comment(linker, "/STACK:102400000,102400000")
2 #include<stdio.h>
3 #include<algorithm>
4 #include<iostream>
5 #include<string.h>
6 #include<stdlib.h>
7 #include<queue>
8 #include<map>
9 #include<math.h>
10 #include<vector>
11 const int N = 1e6+6;
12 using namespace std;
13 typedef long long LL;
14 double x[70000];
15 double v[70000];
16 typedef struct node
17 {
18 double val;
19 int k;
20 } ss;
21 bool cmp(node p,node q)
22 {
23 if(p.val == q.val)
24 return p.k > q.k;
25 else return p.val < q.val;
26 }
27 ss ask[70000*2];
28 bool check(double c,int n);
29 int main(void)
30 {
31 int n;
32 scanf("%d",&n);
33 for(int i = 1; i <= n; i++)
34 scanf("%lf",&x[i]);
35 for(int i = 1; i <= n; i++)
36 scanf("%lf",&v[i]);
37 int t = 100;
38 double ll = 0,rr = 1e10;
39 double acc = -1;
40 while(t)
41 {
42 double mid = (ll+rr)/2;
43 if(check(mid,n))
44 {
45 acc = mid;
46 rr = mid;
47 //printf("%lf\n",mid);
48 }
49 else ll = mid;
50 t--;
51 }
52 printf("%.10f\n",acc);
53 return 0;
54 }
55 bool check(double c,int n)
56 {
57 int cn = 0;
58 double maxx = 1e10;
59 double minn = 0;
60 for(int i = 1; i <= n; i++)
61 {
62 minn = max(minn,x[i] - c*v[i]);
63 maxx = min(maxx,x[i] + c*v[i]);
64 }
65 if(maxx >= minn)return true;
66 return false;
67 }
n*log(n)
B. 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 ...
- 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 ...
随机推荐
- bwa比对软件的使用以及其结果文件(sam)格式说明
一.bwa比对软件的使用 1.对参考基因组构建索引 bwa index -a bwtsw hg19.fa # -a 参数:is[默认] or bwtsw,即bwa构建索引的两种算法,两种算法都是 ...
- php5.6升级7
1. 检查当前安装的 PHP查看当前 PHP 版本 php -v查看当前 PHP 相关的安装包 yum list installed | grep php2. 更换 RPM 源#Centos 5.X: ...
- 巩固javawbe第二天
巩固内容: <!DOCTYPE> 声明 <!DOCTYPE>声明有助于浏览器中正确显示网页. 网络上有很多不同的文件,如果能够正确声明HTML的版本,浏览器就能正确显示网页内容 ...
- PS只能各个工具使用的注意知识点
1.图章工具 <仿制图章工具>使用方法:按住alt点击吸取干净的地方,然后松开alt键,按住鼠标左键拖动或左击 擦拭 图章区域放大缩小,是按住alt键+鼠标右键左右滑动 当图片中多个图 ...
- 数据库ER图基础概念
ER图分为实体.属性.关系三个核心部分.实体是长方形体现,而属性则是椭圆形,关系为菱形. ER图的实体(entity)即数据模型中的数据对象,例如人.学生.音乐都可以作为一个数据对象,用长方体来表示, ...
- redis入门到精通系列(三):key的通用操作和redis内部db的通用操作
五种数据类型都用到了key,key本身是一种字符串,通过key可以获取redis中保存的对象.这一篇博客就将介绍key的通用操作. (一)key基本操作 删除key del key key是否存在 e ...
- 3.2 go WaitGroup代码示例
sync.WaitGroup提供了一种安全的多协程处理方法,内部使用race.atomic来处理,避免了资源竞争及锁的产生. 主要的方法有Add.Done.Wait,可以等待一组协程全部执行完毕后,主 ...
- ClassLoader.loadClass()与Class.forName()的区别《 转》
ClassLoader.loadClass()与Class.forName()区别: ClassLoader.loadClass()与Class.forName()大家都知道是反射用来构造类的方法,但 ...
- synchronized底层浅析(一)
之前说过hashMap,我们知道hashMap是一种非线程安全的集合,主要原因是它在多线程的情况下,插入.删除.扩容的时候容易导致数据丢失或者链表环 那我们也知道ConcurrentHashMap.h ...
- WPF 引用第三方库的控件在设计器加上设计时数据和属性
本文告诉大家如何在 VisualStudio 2022 的 XAML 设计器中,在设计时给第三方控件加上设计用的属性和数据的方法 此功能要求使用不低于 VisualStudio 2019 的 16.8 ...