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 作者 陈越 月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不 ...
随机推荐
- 显示AVI的第一桢
procedure TForm1.Button1Click(Sender: TObject);begin Application.ProcessMessages; MediaPlayer1.Ope ...
- scrollTop实现图像循环滚动(实例1)
<html><head><title>scrollTop实现图像循环滚动(实例1)</title><meta http-equiv="C ...
- 用JDBC如何调用存储过程
package com.huawei.interview.lym; import java.sql.CallableStatement; import java.sql.Connection; imp ...
- lrzsz的安装与配置
1)下载http://freshmeat.sourceforge.net/projects/lrzsz/ 2)tar zxvf lrzsz-0.12.20.tar.gz 3)mv lrzsz-0.12 ...
- jsp页面添加时间
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <body& ...
- ElementTree 解析xml(minidom解析xml大文件时,MemoryError)
在使用minido解析xml文件时,因为文件过大,结果报错MemoryError.查询后得知是因为minidom在解析时是将所有文件放到内存里的,很占用内存,所以要考虑换一种方法来处理xml文件. ...
- input上传图片
1.通过input自身的onchange事件触发: <input id="file" type="file" accept="image/*&q ...
- cdoj第13th校赛初赛L - Lovely princess
http://acm.uestc.edu.cn/#/contest/show/54 L - Lovely princess Time Limit: 3000/1000MS (Java/Others) ...
- 跳跃游戏 12 · Jump Game 12
跳跃游戏 1 [抄题]: [思维问题]: [一句话思路]: [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图]: [一刷]: 由于要用itera ...
- Excel日期格式调整
3-Aug-2008 自定义格式: [$-809]d-mmm-yyyy;@ Aug-2008 自定义格式: [$-809]mmm-yyyy;@