codeforce 702C Cellular Network 二分答案

时间:2021-05-23 17:47:43

http://codeforces.com/contest/702

题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄

思路:直接二分答案

二分太弱,调了半天。。。。。

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define pi acos(-1.0)
const int N = 1e5+;
const int MOD = 1e9+;
#define inf 0x7fffffff
typedef long long LL; void frein(){freopen("in.txt","r",stdin);}
void freout(){freopen("out.txt","w",stdout);}
inline int read(){int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}while(ch>=''&&ch<='') { x=x*+ch-'';ch=getchar();}return x*f;} int a[N];
int b[N]; int main(){
// frein();
// freout();
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++) scanf("%d",&b[i]);
LL l=,r=2e9;
while(l<r){
LL mid=(l+r)>>;
int j=;
bool flag=false;
for(int i=;i<=n;i++){
if(j>m){
flag=true;
break;
}
if(fabs(b[j]-a[i])<=mid){
continue;
}
else{
j++;
i--;
}
}
if(flag){
l=mid+;
}
else{
r=mid;
}
}
printf("%I64d\n",l);
return ;
}