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
  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

题目链接:C. Cellular Network

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

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define INF 0x3f3f3f3f
  4. #define MM(x,y) memset(x,y,sizeof(x))
  5. #define LC(x) (x<<1)
  6. #define RC(x) ((x<<1)+1)
  7. #define MID(x,y) ((x+y)>>1)
  8. typedef pair<int,int> pii;
  9. typedef long long LL;
  10. const double PI=acos(-1.0);
  11. const int N=100010;
  12. int n,m;
  13. int c[N];
  14. int d[N];
  15. int vis[N];
  16. LL min_dis[N];
  17. inline LL ABS(const LL &a)
  18. {
  19. return a>0?a:-a;
  20. }
  21. int main(void)
  22. {
  23. int i,j,k;
  24. while (~scanf("%d%d",&n,&m))
  25. {
  26. for (i=0; i<n; ++i)
  27. {
  28. scanf("%d",&c[i]);
  29. }
  30. for (i=0; i<m; ++i)
  31. {
  32. scanf("%d",&d[i]);
  33. }
  34. LL dx=0;
  35. for (i=0; i<n; ++i)
  36. {
  37. int l=lower_bound(d,d+m,c[i])-d;
  38. int r=upper_bound(d,d+m,c[i])-d-1;
  39. if(l>=m)
  40. l=m-1;
  41. if(r>=m)
  42. r=m-1;
  43. if(r<0)
  44. r=0;
  45. min_dis[i]=min(ABS((LL)c[i]-d[l]),ABS((LL)c[i]-d[r]));
  46. if(min_dis[i]>dx)
  47. dx=min_dis[i];
  48. }
  49. int nm=n+m;
  50. LL l=0,r=2LL*1e9,mid,ans;
  51. while (l<=r)
  52. {
  53. mid=(l+r)>>1;
  54. if(mid>=dx)
  55. {
  56. r=mid-1;
  57. ans=mid;
  58. }
  59. else
  60. l=mid+1;
  61. }
  62. printf("%I64d\n",ans);
  63. }
  64. return 0;
  65. }

Educational Codeforces Round 15 C. Cellular Network(二分)的更多相关文章

  1. Codeforces Educational Codeforces Round 15 C. Cellular Network

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

  2. Educational Codeforces Round 15 Cellular Network

    Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...

  3. Educational Codeforces Round 15 C 二分

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

  4. Educational Codeforces Round 15 A, B , C 暴力 , map , 二分

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 15 (A - E)

    比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...

  6. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Educational Codeforces Round 21 D.Array Division(二分)

    D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  8. Educational Codeforces Round 11 C. Hard Process 二分

    C. Hard Process 题目连接: http://www.codeforces.com/contest/660/problem/C Description You are given an a ...

  9. Educational Codeforces Round 26 F. Prefix Sums 二分,组合数

    题目链接:http://codeforces.com/contest/837/problem/F 题意:如题QAQ 解法:参考题解博客:http://www.cnblogs.com/FxxL/p/72 ...

随机推荐

  1. python 的类变量和对象变量

    python是一种解释性的语言,任何变量可以在使用的时候才声明以及定义,也可以在程序运行的任何位置进行声明和定义新的变量. class Man(object): #直接定义的类的变量,属于类 #其中 ...

  2. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  3. std::map常用方法

    map<string, int> Employees; Employees["Mike C."] = 12306; Employees.insert(make_pair ...

  4. excel数据导入SQLite数据库

    参考:http://blog.baisi.net/?110653/viewspace-6725 1.excel表中最上面一行的字段名留着,留着以后导入的时候对应. 2.保存成csv格式,在选择文件类型 ...

  5. [Android Pro] Android签名与认证详细分析之二(CERT.RSA剖析)

    转载自: http://www.thinksaas.cn/group/topic/335449/ http://blog.csdn.net/u010571535/article/details/899 ...

  6. 如何关闭ie9烦人的提示信息?

    ①Q:如何关闭“IE 限制活动内容”的提示? A:去掉“IE 限制活动内容”的提示: 1. 找到IE的“Internet选项”: 2. 选择“高级”选项卡: 3. 在“设置”下,找到子标题“安全”,将 ...

  7. 会员制实现C2B定制有机农产品,被中粮我买投资的良食网这样卖有机生鲜

    前几天,中粮我买网战略投资了位于深圳的有机生鲜自营平台良食网,宣布双方将会在供应链上展开合作.然而良食网对大家来说还是比较陌生的,为此36氪专访了良食网的创始人唐忠. 良食网成立于2011年,是一家以 ...

  8. Ubuntu小点汇总,更新中...

    转自:http://blog.csdn.net/zxz_tsgx/article/details/39713627 昨天重装了Ubuntu14.04 64位版,又被一些基础操作/设置给搞怕了,以前安装 ...

  9. matlab练习程序(最小包围矩形)

    又是计算几何,我感觉最近对计算几何上瘾了. 当然,工作上也会用一些,不过工作上一般直接调用boost的geometry库. 上次写过最小包围圆,这次是最小包围矩形,要比最小包围圆复杂些. 最小包围矩形 ...

  10. mysql之对表的操作

    1. 表的基本概念 在数据库中,表是一种非常重要的数据库对象,是组成数据库的基本对象,由若干个字段组成,主要用来储存数据记录. 表中的数据库对象包含列,索引和触发器. 列:也称属性列,在具体创建表时必 ...