题目链接:
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 题意: 给每个城市找一个供给,问最小的半径是多少; 思路: 二分; AC代码:
/************************************************
┆ ┏┓ ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃ ┃ ┆
┆┃ ━ ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃ ┃ ┆
┆┃ ┻ ┃ ┆
┆┗━┓ ┏━┛ ┆
┆ ┃ ┃ ┆
┆ ┃ ┗━━━┓ ┆
┆ ┃ AC代马 ┣┓┆
┆ ┃ ┏┛┆
┆ ┗┓┓┏━┳┓┏┛ ┆
┆ ┃┫┫ ┃┫┫ ┆
┆ ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=(1<<8);
const double eps=1e-8; int a[N],b[N],n,m; int check2(int x)
{
int l=1,r=m;
while(l<=r)
{
int mid=(l+r)>>1;
if(b[mid]>x)r=mid-1;
else l=mid+1;
}
if(r==0)r=1;
return r;
}
int check1(int x)
{
int l=1,r=m;
while(l<=r)
{
int mid=(l+r)>>1;
if(b[mid]<x)l=mid+1;
else r=mid-1;
}
if(l>m)l=m;
return l;
} int main()
{
read(n);read(m);
For(i,1,n)read(a[i]);
For(i,1,m)read(b[i]);
int ans=0;
For(i,1,n)
{ int l=check1(a[i]);
int r=check2(a[i]);
//cout<<l<<" "<<r<<endl;
int temp=min(abs(b[l]-a[i]),abs(b[r]-a[i]));
ans=max(ans,temp); }
cout<<ans<<endl; return 0;
}