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 4
    -3 0
output
  1. 4
input
  1. 5 3
    1 5 10 14 17
    4 11 15
output
  1. 3

这题好迷的

就是对于每个a[i],求出min{ |a[i]-b[j]| }

然后再在n个数中取个最大值输出

简直就是模拟嘛

这里求min我又用了二分(应该三分也可以,吧。毕竟有个abs就是单峰的)

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<ctime>
  8. #define LL long long
  9. #define inf 0x7ffffff
  10. #define pa pair<int,int>
  11. #define pi 3.1415926535897932384626433832795028841971
  12. using namespace std;
  13. inline LL read()
  14. {
  15. LL x=,f=;char ch=getchar();
  16. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  17. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  18. return x*f;
  19. }
  20. inline void write(LL a)
  21. {
  22. if (a<){printf("-");a=-a;}
  23. if (a>=)write(a/);
  24. putchar(a%+'');
  25. }
  26. inline void writeln(LL a){write(a);printf("\n");}
  27. int n,m,ans;
  28. int a[];
  29. int b[];
  30. int dist[];
  31. inline int bsearch(int l,int r,int dat)
  32. {
  33. int ans=;
  34. while (l<=r)
  35. {
  36. int mid=(l+r)>>;
  37. if (b[mid]<dat){ans=mid;l=mid+;}
  38. else r=mid-;
  39. }
  40. return ans;
  41. }
  42. int main()
  43. {
  44. n=read();m=read();
  45. for(int i=;i<=n;i++)a[i]=read();
  46. sort(a+,a+n+);
  47. for (int i=;i<=m;i++)b[i]=read();
  48. sort(b+,b+m+);
  49. int now=;
  50. for (int i=;i<=n;i++)
  51. {
  52. int fnd=bsearch(,m,a[i]);
  53. if (fnd==)fnd++;dist[i]=abs(b[fnd]-a[i]);
  54. if (fnd!=m)dist[i]=min(abs(b[fnd]-a[i]),abs(b[fnd+]-a[i]));
  55. ans=max(ans,dist[i]);
  56. }
  57. printf("%d\n",ans);
  58. }

cf702D

cf702C Cellular Network的更多相关文章

  1. 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. UVA 1456 六 Cellular Network

    Cellular Network Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  3. Educational Codeforces Round 15 Cellular Network

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

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

  5. Educational Codeforces Round 15_C. Cellular Network

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

  6. codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏

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

  7. codeforces 702C C. Cellular Network(水题)

    题目链接: C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input st ...

  8. CodeForce-702C Cellular Network(查找)

    Cellular Network CodeForces - 702C 给定 n (城市数量) 和 m (灯塔数量): 给定 a1~an 城市坐标: 给定 b1~bm 灯塔坐标: 求出灯塔照亮的最小半径 ...

  9. Codeforces 702C Cellular Network

    题目:这里 题意:一条数轴上,有n个城市和m个塔,分别给出城市的位置和塔的位置,每个塔有个覆盖范围,问能将所有城市都覆盖的塔的最小范围是多少,一个城市只要被至少一个塔 覆盖就行. 可以利用贪心的思想模 ...

随机推荐

  1. 怎样使用svn开发项目

    那么首先什么是svn呢?官方有很好的解释,我说一下个人简单的理解,svn就是开源的版本控制软件, 那么什么是版本呢?简单的说版本就是标记,比如你买了一本书,同样的书名,但是版本不一定一样, 因为里面可 ...

  2. sqlserver 时间转换

    sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(), 时间一, ) 结果:-- :/*时间一般 ...

  3. PetaPoco 存储过程

    1 执行不带参数的存储过程 public List<dynamic> ceshiProc() { string sql = @"EXEC [dbo].[p_ceshi1]&quo ...

  4. 游标中的static参数

    以下测试用例将演示,使用static的游标和不使用的区别: if object_id(N't_test',N'u') is not null drop table t_test go create t ...

  5. wpf 大控件 打印 将控件转成 xps格式 并分页打印

    //PayRollPrintList:要打印的 list 可换成自己要打印的类型 private List<PayRoll> _PayRollPrintList = new List< ...

  6. MyEclipse起步Tomcat报错“A configuration error occurred during…” MyEclipse起步Tomcat报错“A configuration error occurred during…”

  7. 用layer添加UIView的动画

    项目有时会遇到用UIView 添加动画的情况,这里我觉得在layer上添加动画比较好,因为可以详细地设定动画属性,方便理解 下面是一个旋转动画: -(void)roundBtnAction:(id)s ...

  8. IOS-UI-UILable

    //用于文本展示 UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 200, 300)]; //使用测色器自选颜色 ...

  9. (java)从零开始之--观察者设计模式Observer

    观察者设计模式:时当一个对象发生指定的动作时,要通过另外的对象做出相应的处理. 步骤: 1. A对象发生指定的动作是,要通知B,C,D...对象做出相应的处理,这时候应该把B,C,D...对象针对A对 ...

  10. [LeetCode OJ] Best Time to Buy and Sell Stock I

    Say you have an array for which the ith element is the price of a given stock on day i. If you were ...