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

题目链接:C. Cellular Network

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

代码:

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define MM(x,y) memset(x,y,sizeof(x))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0);
const int N=100010;
int n,m;
int c[N];
int d[N];
int vis[N];
LL min_dis[N];
inline LL ABS(const LL &a)
{
return a>0?a:-a;
}
int main(void)
{
int i,j,k;
while (~scanf("%d%d",&n,&m))
{
for (i=0; i<n; ++i)
{
scanf("%d",&c[i]);
}
for (i=0; i<m; ++i)
{
scanf("%d",&d[i]);
}
LL dx=0;
for (i=0; i<n; ++i)
{
int l=lower_bound(d,d+m,c[i])-d;
int r=upper_bound(d,d+m,c[i])-d-1;
if(l>=m)
l=m-1;
if(r>=m)
r=m-1;
if(r<0)
r=0;
min_dis[i]=min(ABS((LL)c[i]-d[l]),ABS((LL)c[i]-d[r]));
if(min_dis[i]>dx)
dx=min_dis[i];
}
int nm=n+m;
LL l=0,r=2LL*1e9,mid,ans;
while (l<=r)
{
mid=(l+r)>>1;
if(mid>=dx)
{
r=mid-1;
ans=mid;
}
else
l=mid+1;
}
printf("%I64d\n",ans);
}
return 0;
}

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. 在Spring3中,配置DataSource的方法有6种。

    第一种:beans.xml Xml代码 收藏代码<bean id="dataSource" class="org.apache.commons.dbcp.Basic ...

  2. Adaboost算法结合Haar-like特征

    Adaboost算法结合Haar-like特征 一.Haar-like特征 目前通常使用的Haar-like特征主要包括Paul Viola和Michal Jones在人脸检测中使用的由Papageo ...

  3. hadoop中常见的问题

    一.在root下进行格式化 这样很糟糕 这样的话,若是第一次装的话,我的建议是将生成的文件都删掉,恢复到最开始的状态, 1. 首先你需要删除 vi conf/hdfs-site.xml   配置文件的 ...

  4. SQL 函数

    一.数学函数 数学函数主要用于处理数字,包括整型.浮点数等. ABS(x) 返回x的绝对值 SELECT ABS(-1) -- 返回1 CEIL(x),CEILING(x) 返回大于或等于x的最小整数 ...

  5. FileHelper-文件操作辅助类

    using System; using System.Collections.Generic; using System.IO; using System.Text; namespace Whir.S ...

  6. struts.xml中可以使用el表达式和ognl表达式

    转自:http://blog.csdn.net/hzc543806053/article/details/7538723 文件上传链接: 1)Servlet 文件上传 ————  点击打开链接 2)S ...

  7. TextView属性大全

    今天研究了TextView一天了,发现网上有一篇讲TextView属性的,非常全,收藏一下先. 发现TextView有一个比较大的问题,就是文字排版的问题,遇到数字,字母,符号等就会有问题,目前还没有 ...

  8. [hive小技巧]同一份数据多种处理

    其实就是from表时,可以插入到多个表. sql语句的模板如下: from history insert overwrite sales select * where actino='purchase ...

  9. 转-CSS3 圆角(border-radius)

    CSS3 圆角(border-radius)   前缀 例1 例2:无边框 书写顺序 其它 支持性 值:半径的长度 前缀 -moz(例如 -moz-border-radius)用于Firefox -w ...

  10. EF Code First 数据库迁移Migration剖析

    1.简介 Entity Framework 的Code First 方式,提供了一种方式:编写模型Model,生成模型变更,根据模型变更修改数据库. 而其所以来的环境就是强大的Nuget,如果还在是V ...