博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Educational Codeforces Round 15 C. Cellular Network(二分)
阅读量:5377 次
发布时间:2019-06-15

本文共 2640 字,大约阅读时间需要 8 分钟。

 

C. Cellular Network
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 rfrom this tower.

Input

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.

Output

Print minimal r so that each city will be covered by cellular network.

Examples
input
3 2-2 2 4-3 0
output
4
input
5 31 5 10 14 174 11 15
output
3

 

题目链接:

让每一个城市都可以被供给,也就是说每一个发电站的距离向左右延伸后要把城市最小~最大范围全部覆盖到,想了一会儿感觉是找每一个城市的最近供给站的距离,然后取最大值作为标准,然后进行二分……,然后怎么找这个最近的供给站呢?还是二分……,找的时候注意边界就可以了

代码:

 

#include
using namespace std;#define INF 0x3f3f3f3f#define MM(x,y) memset(x,y,sizeof(x))#define LC(x) (x<<1)#define RC(x) ((x<<1)+1)#define MID(x,y) ((x+y)>>1)typedef pair
pii;typedef long long LL;const double PI=acos(-1.0);const int N=100010;int n,m;int c[N];int d[N];int vis[N];LL min_dis[N];inline LL ABS(const LL &a){ return a>0?a:-a;}int main(void){ int i,j,k; while (~scanf("%d%d",&n,&m)) { for (i=0; i
=m) l=m-1; if(r>=m) r=m-1; if(r<0) r=0; min_dis[i]=min(ABS((LL)c[i]-d[l]),ABS((LL)c[i]-d[r])); if(min_dis[i]>dx) dx=min_dis[i]; } int nm=n+m; LL l=0,r=2LL*1e9,mid,ans; while (l<=r) { mid=(l+r)>>1; if(mid>=dx) { r=mid-1; ans=mid; } else l=mid+1; } printf("%I64d\n",ans); } return 0;}

 

转载于:https://www.cnblogs.com/Blackops/p/5766275.html

你可能感兴趣的文章
[sql]mysql启停脚本
查看>>
[elk]Mutate filter plugin增删改查字段
查看>>
Java内功心法,行为型设计模式
查看>>
向github项目push代码后,Jenkins实现其自动构建
查看>>
jquery中的ajax方法参数的用法和他的含义
查看>>
BZOJ 1226: [SDOI2009]学校食堂Dining
查看>>
数组去重的几种方法
查看>>
包装类的自动装箱与拆箱
查看>>
ShareSDk的使用
查看>>
android使用web加载网页的js问题
查看>>
poj 1068 Parencodings
查看>>
docker 数据卷管理
查看>>
如何让一个div的大小,从某一个特定值开始,随内容的增加而自动变化?
查看>>
P1977 出租车拼车(DP)
查看>>
iOS开发--完整项目
查看>>
我的博客园皮肤模板
查看>>
正则表达式
查看>>
java基础:不同进制的表现形式
查看>>
Base64转换为blob对象
查看>>
gulp自动化压缩合并、加版本号解决方案
查看>>