CF 702C Cellular Network
来源:互联网 发布:python idle无法打开 编辑:程序博客网 时间:2024/05/22 04:57
#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){ long long n,m; long long a[100005],b[100005]; while(~scanf("%lld%lld",&n,&m)) { for(int i=1; i<=n; i++) scanf("%lld",&a[i]); for(int i=1; i<=m; i++) scanf("%lld",&b[i]); b[0]=-200000000000; b[m+1]=200000000000; long long sum=0; long long ans=0; for(int i=1; i<=n; i++) { int x=lower_bound(b+1,b+m+1,a[i])-b;//二分每个村庄 sum=min(abs(b[x]-a[i]),abs(b[x-1]-a[i]));//选每个最小的距离 ans=max(ans,sum);//最后选最大的 } printf("%lld\n",ans); }}
You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from this tower.
Your task is to find minimal r that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than r.
If r = 0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than r from this tower.
The first line contains two positive integers n and m (1 ≤ n, m ≤ 105) — the number of cities and the number of cellular towers.
The second line contains a sequence of n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates ai are given in non-decreasing order.
The third line contains a sequence of m integers b1, b2, ..., bm ( - 109 ≤ bj ≤ 109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates bj are given in non-decreasing order.
Print minimal r so that each city will be covered by cellular network.
3 2-2 2 4-3 0
4
5 31 5 10 14 174 11 15
3
- CF 702C Cellular Network
- Cf Edu 15 C Cellular Network 二分
- codeforces-702C-Cellular Network
- codeforces 702C Cellular Network
- codeforces 702C Cellular Network
- Codeforces 702C Cellular Network【二分+思维】CF的题好多二分啊~
- 【CodeForces】702C - Cellular Network(二分)
- 【Codeforces】-702C-Cellular Network(二分)
- coderforces 702C Cellular Network(二分)
- CodeForces 702 C. Cellular Network(水~)
- codeforces 702C Cellular Network 二分
- codeforces 702C Cellular Network(二分+尺取)
- Educational Codeforces Round 15 C. Cellular Network
- Educational Codeforces Round 15 C. Cellular Network(二分)
- Educational Codeforces Round 15, problem: (C) Cellular Network
- Educational Codeforces Round 15 C. Cellular Network (二分)
- Educational Codeforces Round 15 C Cellular Network(二分)
- Cellular Network LA4731
- 关于斜率优化DP
- Windows64 bit 环境下安装配置Redis
- STL中set用法详解
- mysql数据库中的索引
- 设计模式之桥接模式
- CF 702C Cellular Network
- 五大常用算法:分治、动态规划、贪心、回溯和分支界定
- Spring与Hibernate结合使用
- Day1 Markdown for My CSDN blog
- Android开发02_四种常用监听
- leetcode 7 --- Reverse Integer
- mysql 主从复制配置
- 从ui框架到view的事件分发
- Android.mk 文件语法详解