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





  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<queue>
  6. #include<vector>
  7. #include<algorithm>
  8. using namespace std;
  9. #define inf 0x3f3f3f3f
  10.  
  11. long long int a[100005];
  12. long long int b[100005];
  13. long long int dp[100005];
  14. int m,n;
  15. int main()
  16. {
  17. while(~scanf("%d%d",&m,&n))
  18. {
  19. for(int i=0; i<m; i++)
  20. {
  21. scanf("%I64d",&a[i]);
  22. }
  23.  
  24. for(int j=0; j<n; j++)
  25. {
  26. scanf("%I64d",&b[j]);
  27. }
  28.  
  29. sort(a,a+m);
  30. sort(b,b+n);
  31. memset(dp,inf,sizeof dp);
  32. int q=0,p=0;
  33. while(q<m&&p<n)
  34. {
  35. if(abs(a[q]-b[p])<=dp[q])
  36. {
  37. dp[q]=abs(a[q]-b[p]);
  38. p++;
  39. }
  40. else
  41. {
  42. p--;
  43. q++;
  44. }
  45. }
  46. while(q<m)
  47. {
  48. dp[q]=abs(a[q]-b[n-1]);
  49. q++;
  50. }
  51. long long sum=-1;
  52. for(int i=0; i<m; i++)
  53. sum=max(sum,dp[i]);
  54. printf("%I64d\n",sum);
  55. }
  56. return 0;
  57. }

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. java编写一个汽车类,有属性:品牌、型号、排量、速度,有方法:启动、加速、转弯、刹车、息火

    /* * 汽车实体类 * 类里面有属性和方法 */public class Car {    String  brand;   //汽车品牌    String modelNumber; //汽车型号 ...

  2. 常用类一一时间处理相关类一一java.util.Tomezone(java.util.Calendar , java.util.Date , java.text.DateFormat)

    时间处理相关类 时间是一个一维的东东.所以,我们需要一把刻度尺来区表达和度量时间.在计算机世界,我们把1970 年 1 月 1 日 00:00:00定为基准时间,每个度量单位是毫秒(1秒的千分之一). ...

  3. 读取数据库信息并生成表设计文档Word版本

    1.参考C#代码 using Help.DBAccessLayer.Business; using Help.DBAccessLayer.Model.SqlGenerator; using Newto ...

  4. 关于关闭TAB,IFRAME占用的内存不能释放问题

    资料来源:http://jxd-zxf.iteye.com/blog/1440611 使用TAB时注意,如果TAB是引用IFRAME,关闭TAB时IFRAME不会被销毁从而导致内存不能释放,大量使用T ...

  5. while循环出现的问题

    1 int c = 0; while(c<=100) c++ } 自己看了很久没看出来,后来请教同学才知道,变量g是不能写在一开始的,因为while循环只是循环自己的那个花括号内的指令,不会循环 ...

  6. 注册google账号 解决国内手机注册失败的问题

    1. PC端下载夜神安卓模拟器.安装,启动. 2. 在模拟器里的市场应用里下载qq邮箱. 3. 启动邮箱,选择gmail,注册.后续一切顺利. 这是迄今为止,唯一注册顺利的方法.其他方法,手机验证一关 ...

  7. np.random.randn()、np.random.rand()、np.random.randint()

    (1)np.random.randn()函数 语法: np.random.randn(d0,d1,d2……dn) 1)当函数括号内没有参数时,则返回一个浮点数: 2)当函数括号内有一个参数时,则返回秩 ...

  8. 【英宝通Unity4.0公开课学习 】(六)76讲到90讲

    还是关于Mecanim动画的内容. 这些讲的每讲长度明显比前面的长,而且很多都涉及到脚本编写. 不过我还是2倍速给略览过去了,主要目的就是学个框架嘛 :) 1. Blend Tree 可嵌套. 可理解 ...

  9. 使用ecstore-sdk开发包制作易开店和启明星模板

    前言: 尽管商派官网有模板开发教程,但是诸多方面太过笼统.我等平庸之辈,纵使细心研读,潜心修炼,亦未能品味练功境界,领悟其中真谛. 商派有云,此九阳真经不用您挥刀****本人却感觉此教程令人抓狂,无人 ...

  10. 兼容主流浏览器的css渐变色

    网页中的渐变色区域,渐变色背景,一般都是通过ps图片方法来实现,但是图片放得多了会影响网页的打开速度,本文介绍的就是用纯 CSS 实现 IE .Firefox.Chrome 和 和Safari都支持的 ...