http://codeforces.com/contest/702
题意:n个村庄,m个机站,问机站最短半径覆盖完所有村庄
思路:直接二分答案
二分太弱,调了半天。。。。。
1 // #pragma comment(linker, "/STACK:102c000000,102c000000") 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <sstream> 6 #include <string> 7 #include <algorithm> 8 #include <list> 9 #include <map> 10 #include <vector> 11 #include <queue> 12 #include <stack> 13 #include <cmath> 14 #include <cstdlib> 15 // #include <conio.h> 16 using namespace std; 17 #define pi acos(-1.0) 18 const int N = 1e5+10; 19 const int MOD = 1e9+7; 20 #define inf 0x7fffffff 21 typedef long long LL; 22 23 void frein(){freopen("in.txt","r",stdin);} 24 void freout(){freopen("out.txt","w",stdout);} 25 inline int read(){int x=0,f=1;char ch=getchar();while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1;ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘;ch=getchar();}return x*f;} 26 27 int a[N]; 28 int b[N]; 29 30 int main(){ 31 // frein(); 32 // freout(); 33 int n,m; 34 scanf("%d%d",&n,&m); 35 for(int i=1;i<=n;i++) scanf("%d",&a[i]); 36 for(int i=1;i<=m;i++) scanf("%d",&b[i]); 37 LL l=0,r=2e9; 38 while(l<r){ 39 LL mid=(l+r)>>1; 40 int j=1; 41 bool flag=false; 42 for(int i=1;i<=n;i++){ 43 if(j>m){ 44 flag=true; 45 break; 46 } 47 if(fabs(b[j]-a[i])<=mid){ 48 continue; 49 } 50 else{ 51 j++; 52 i--; 53 } 54 } 55 if(flag){ 56 l=mid+1; 57 } 58 else{ 59 r=mid; 60 } 61 } 62 printf("%I64d\n",l); 63 return 0; 64 }
时间: 2024-11-05 01:11:48