coderforces 702C Cellular Network(二分)
来源:互联网 发布:消防大数据平台 编辑:程序博客网 时间:2024/05/22 10:30
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
题意:给你n个城市和m和信号塔的坐标位置,信号塔的覆盖半径为r,问你能把所有城市都覆盖的r的最小值
思路:枚举每个城市,用二分查找距离这个城市最近的信号塔,并记录它们之间的距离,最后找到城市与信号塔之间的距离中的最大值即为所求,具体见代码。。
#include <cstdio>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;const int maxn = 100010;int n,m;int a[maxn];int b[maxn];int main(){ while(~scanf("%d%d",&n,&m)) { for(int i = 0 ; i < n ; i++) scanf("%d",&a[i]); for(int j = 0 ; j < m ; j++) scanf("%d",&b[j]); int ans = 0; for(int i = 0 ; i < n ; i++) { int l = 0 , r = m-1; while(r - l > 1) { int mid = (l + r) >> 1; if(b[mid] >= a[i]) r = mid; else l = mid; } int cnt = min(abs(b[l]-a[i]),abs(b[r]-a[i])); ans = max(ans,cnt); } printf("%d\n",ans); } return 0;}
- coderforces 702C Cellular Network(二分)
- 【CodeForces】702C - Cellular Network(二分)
- 【Codeforces】-702C-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 C Cellular Network(二分)
- CodeForces 702 C. Cellular Network(水~)
- Cf Edu 15 C Cellular Network 二分
- codeforces-702C-Cellular Network
- CF 702C Cellular Network
- codeforces 702C Cellular Network
- codeforces 702C Cellular Network
- Codeforces702C - Cellular Network(二分)
- codeforces702C Cellular Network(二分)
- Codeforces 702C Cellular Network【二分+思维】CF的题好多二分啊~
- Educational Codeforces Round 15 C. Cellular Network
- 记一次Linux系统被入侵的排查过程(一)
- iOS平台下cookie的使用
- [原创]unity教程之2048游戏01。
- [原创]unity教程之2048游戏02。
- [原创]unity教程之2048游戏03
- coderforces 702C Cellular Network(二分)
- [原创]unity3D学习【功能实现】之七:Animator动画以及传递参数,简单功能
- 【转载】C#中Dictionary的作用及用…
- unity3D学习【功能实现】之八:对象池学习一
- unity3D学习【功能实现】之八:对象池讲学习二
- 第六周 进程的描述和进程的创建
- MyEclipse个性化代码注释模板
- unity3D学习【功能实现】之九:鼠标拖动图片
- unity3D学习【功能实现】之十:关卡制作scroll rect应用以及一些代码