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 r from 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 3
1 5 10 14 17
4 11 15
output
3
题目的意思是在一条直线上,给出两类点,一种是城市,一种是信号台,问信号台的覆盖范围最小为多少才能覆盖所有城市。
实际上就是找出每个城市理他最近的信号台的距离去最大值即可。
我们先将城市和信号台排个序,然后定义两个下标p,q进行访问城市和信号台,因为在排序的情况下,如果后一个信号台比前一个距离某城市更近,那么它一定比前一个距离下一个城市更近,我们用dp数组记录下所有最近距离,在去最大即可





#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f long long int a[100005];
long long int b[100005];
long long int dp[100005];
int m,n;
int main()
{
while(~scanf("%d%d",&m,&n))
{
for(int i=0; i<m; i++)
{
scanf("%I64d",&a[i]);
} for(int j=0; j<n; j++)
{
scanf("%I64d",&b[j]);
} sort(a,a+m);
sort(b,b+n);
memset(dp,inf,sizeof dp);
int q=0,p=0;
while(q<m&&p<n)
{
if(abs(a[q]-b[p])<=dp[q])
{
dp[q]=abs(a[q]-b[p]);
p++;
}
else
{
p--;
q++;
}
}
while(q<m)
{
dp[q]=abs(a[q]-b[n-1]);
q++;
}
long long sum=-1;
for(int i=0; i<m; i++)
sum=max(sum,dp[i]);
printf("%I64d\n",sum);
}
return 0;
}

codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏的更多相关文章

  1. Ubuntu vim+ ctags(包含系统函数) + taglist 配置 分类: vim ubuntu 2015-06-09 18:19 195人阅读 评论(0) 收藏

    阅读大型代码,我们经常需要打开很多的代码文件,搜索各种定义.windows下用惯了ide的朋友,转战Linux的时候可能会觉得很难受,找不到合适的阅读工具.其实万能的vim就可以实现.下面介绍一下vi ...

  2. python字符串中包含Unicode插入数据库乱码问题 分类: Python 2015-04-28 18:19 342人阅读 评论(0) 收藏

    之前在编码的时候遇到一个奇葩的问题,无论如何操作,写入数据库的字符都是乱码,之后是这样解决的,意思就是先解码,然后再插入数据库 cost_str = json.dumps(cost_info) cos ...

  3. c++map的用法 分类: POJ 2015-06-19 18:36 11人阅读 评论(0) 收藏

    c++map的用法 分类: 资料 2012-11-14 21:26 10573人阅读 评论(0) 收藏 举报 最全的c++map的用法 此文是复制来的0.0 1. map最基本的构造函数: map&l ...

  4. HDU 1166敌兵布阵 2016-09-14 18:58 89人阅读 评论(0) 收藏

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. Hdu1429 胜利大逃亡(续) 2017-01-20 18:33 53人阅读 评论(0) 收藏

    胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Subm ...

  6. Doubles 分类: POJ 2015-06-12 18:24 11人阅读 评论(0) 收藏

    Doubles Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19954   Accepted: 11536 Descrip ...

  7. 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏

    制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...

  8. highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏

    /*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...

  9. 团体程序设计天梯赛L2-003 月饼 2017-03-22 18:17 42人阅读 评论(0) 收藏

    L2-003. 月饼 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不 ...

随机推荐

  1. VCL编写笔记整理

    unit hzqEdit1; interface uses  SysUtils, Classes, Controls, StdCtrls; type  TEditDataType = (dtpStri ...

  2. 吴裕雄 实战python编程(2)

    from urllib.parse import urlparse url = 'http://www.pm25x.com/city/beijing.htm'o = urlparse(url)prin ...

  3. SO\PR回写的数据如下

    insert into OUT_ORDER_RES ---JAVA FOR PR ) as LGORT ,'SAPRFC' as ERNAM,out_pr.due_datetime,out_pr.so ...

  4. 将2020年交期的PR回写出来了

    OUT_pr表中的交期为2020年和2019年,不应该 回写的PR却回写出来了 优化如下:

  5. Cannot resolve class or package 'dbcp' Cannot resolve class 'BasicDataSource'

    在applicationContext.xml中配置数据源时,报错如下: Cannot resolve class or package 'dbcp' Cannot resolve class 'Ba ...

  6. 最短路径Dijkstra算法(邻接矩阵)

    Dijkstra算法的原理: 从某个源点到其余各顶点的最短路径,即单源点最短路径(仅适合非负权值图).单源点最短路径是指:给定带权有向图G和源点v,求从v到G中其余各顶点的最短路径.迪杰斯特拉(Dij ...

  7. LibreOJ 6277 数列分块入门 1(分块)

    题解:感谢hzwer学长和loj让本蒟蒻能够找到如此合适的入门题做. 这是一道非常标准的分块模板题,本来用打标记的线段树不知道要写多少行,但是分块只有这么几行,极其高妙. 代码如下: #include ...

  8. sqserver2008触发器

    @参考博文 先上代码 先建个表用于测试 CREATE TRIGGER INSERT_forbidden on s after INSERT AS BEGIN RAISERROR(,) ROLLBACK ...

  9. 找不到reportviewer控件在哪儿

    請自行加入ReportViewer(9.0)到工具箱之中. 如下圖,

  10. .NET发送请求(get/post/http/https),携带json数据,接收json数据

    C#发送https请求有一点要注意: ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateVa ...