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 ...
随机推荐
- EXCEL-排名前三名显示小红旗,后三名显示小黑旗
总结(用的WPS):第一步:用=IF(RANK(数值,引用范围) <=3,"小红旗",IF(RANK(数值,引用,1) <=3,"小黑旗",&quo ...
- Shell学习(一)——Shell简介
参考博客: [1]Shell简介
- linux之sar命令详解
sar(System Activity Reporter系统活动情况报告)是目前Linux上最为全面的系统性能分析工具之一,可以从多个方面对系统的活动进行报告,包括:文件的读写情况.系统调用的使用情况 ...
- Linux学习 - 输入输出重定向,管道符,通配符
一.键盘输入读取read read [选项] [变量名] -p [显示信息] 在等待read输入时,输出提示信息 -t [秒数] 指定read输入等待时间 -n [字符数] 指定read只接收n个字符 ...
- docker配置国内阿里云镜像源
使用docker默认镜像源下载镜像会很慢,因此很多情况下,我们在安装完docker以后都会修改为国内的镜像,这样在下载镜像的时候就不用等那么长时间了. 配置docker的镜像为阿里云镜像 方法一 $ ...
- Redis数据类型内部编码规则及优化方式
Redis的每个键值都是使用一个redisObject结构体保存的,redisObject的定义如下: typedef struct redisObject { unsigned type:4; un ...
- Function overloading and const keyword
Predict the output of following C++ program. 1 #include<iostream> 2 using namespace std; 3 4 c ...
- spring cloud 通过 ribbon 实现客户端请求的负载均衡(入门级)
项目结构 环境: idea:2020.1 版 jdk:8 maven:3.6.2 1. 搭建项目 ( 1 )父工程:spring_cloud_demo_parent pom 文件 <?xml v ...
- linux-源码软件管理-yum配置
总结如下:1.源码配置软件管理2.配置yum本地源和网络源及yum 工作原理讲解3.计算机硬盘介绍 1.1 源码管理软件 压缩包管理命令: # 主流的压缩格式包括tar.rar.zip.war.gzi ...
- 【Java】【IDE】【Jetbrain Idea】Intellij IDEA 快捷键整理
[常规] Ctrl+Shift + Enter,语句完成 "!",否定完成,输入表达式时按 "!"键 Ctrl+E,最近的文件 Ctrl+Shift+E,最近更 ...