codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏
3 seconds
256 megabytes
standard input
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.
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 3
1 5 10 14 17
4 11 15
3
#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) 收藏的更多相关文章
- Ubuntu vim+ ctags(包含系统函数) + taglist 配置 分类: vim ubuntu 2015-06-09 18:19 195人阅读 评论(0) 收藏
阅读大型代码,我们经常需要打开很多的代码文件,搜索各种定义.windows下用惯了ide的朋友,转战Linux的时候可能会觉得很难受,找不到合适的阅读工具.其实万能的vim就可以实现.下面介绍一下vi ...
- python字符串中包含Unicode插入数据库乱码问题 分类: Python 2015-04-28 18:19 342人阅读 评论(0) 收藏
之前在编码的时候遇到一个奇葩的问题,无论如何操作,写入数据库的字符都是乱码,之后是这样解决的,意思就是先解码,然后再插入数据库 cost_str = json.dumps(cost_info) cos ...
- 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 ...
- 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 ...
- Hdu1429 胜利大逃亡(续) 2017-01-20 18:33 53人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- Doubles 分类: POJ 2015-06-12 18:24 11人阅读 评论(0) 收藏
Doubles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19954 Accepted: 11536 Descrip ...
- 移植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 ...
- highgui.h备查 分类: C/C++ OpenCV 2014-11-08 18:11 292人阅读 评论(0) 收藏
/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMP ...
- 团体程序设计天梯赛L2-003 月饼 2017-03-22 18:17 42人阅读 评论(0) 收藏
L2-003. 月饼 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不 ...
随机推荐
- Haskell语言学习笔记(21)Array
Ix 数组下标类型 Prelude> :m +Data.Array Prelude Data.Array> data Colour = Red | Orange | Yellow | Gr ...
- 迷你MVVM框架 avalonjs 学习教程12、数据联动
在许多表单应用,我们经常遇到点击一个复选框(或下拉框)会引发旁边的复选框(或下拉框)发生改变,这种联动效果用avalon来做是非常简单的.在avalon里,存在各种绑定回调与$watch回调,完全满足 ...
- python并行编程
一.编程思想 并行编程的思想:分而治之,有两种模型 1.MapReduce:将任务划分为可并行的多个子任务,每个子任务完成后合并得到结果 例子:统计不同形状的个数. 先通过map进行映射到多个子任务, ...
- Ubuntu下面网络固定ip
https://jingyan.baidu.com/article/e5c39bf5bbe0e739d7603396.html
- General error 2006 MySQL server has gone away
写入配置文件的办法: max_allowed_packet = 16M //但是这种有时候不支持,1024*1024*16这种有的也不支持 max_allowed_packet = 16777216 ...
- golang获取IP地址
ip:=this.Ctx.Request.RemoteAddr ip=ip[0:strings.LastIndex(ip, ":")]
- C# split分割多个字符
string[] myAgent = agentInfo.Split(new string[] { "$#$" }, StringSplitOptions.None);
- TZOJ 2755 国际象棋(广搜+哈希)
描述 在n*n的国际象棋棋盘中,给定一“马(Knight)”和一“后(Queen)”的位置,问“马”能否在m步之内(包括m步)到达“后”的位置?马的走法是:每步棋先横走或直走一格,然后再斜走一格,即走 ...
- Linux 下 FastDFS v5.08 分布式文件系统的安装
一.系统安装目录 源代码包目录 /data/wwwroot libevent安装目录 /usr/local/libevent FastDFS安装目录 /data/fastdfs nginx安装目录 / ...
- OSGi 系列(十三)之 Configuration Admin Service
OSGi 系列(十三)之 Configuration Admin Service OSGi 的 CM 就是 Configuration Admin Service,是用于管理 Bundle 属性.并在 ...