1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| #include <algorithm> #include <iostream> #include <cstdio> #include <cctype> #include <cmath>
using namespace std;
typedef long double db;
inline int read() { int x=0,f=1; char ch=getchar(); while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar(); while (isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return x*f; }
const int N=1005; const int V=N<<1; const db EPS=1e-4; const db INF=1e+9; const db pi=acosl(-1); const int ERROR=-100000;
inline bool equ(db x,db y){return fabs(x-y)<=EPS;} inline int sgn(db x){return equ(x,0.)?0:(x<0?-1:1);}
struct P { db x,y;
inline P (db x_=0.,db y_=0.){x=x_,y=y_;}
inline P operator+(P const p)const{return P(x+p.x,y+p.y);} inline P operator-(P const p)const{return P(x-p.x,y-p.y);} inline P operator*(db const k)const{return P(x*k,y*k);}
inline db operator*(P const p)const{return x*p.x+y*p.y;} inline db operator^(P const p)const{return x*p.y-y*p.x;}
inline db mod2()const{return (*this)*(*this);} inline db mod()const{return sqrt(fabs(mod2()));}
inline db arg(){return atan2(y,x);} }pts[V];
int n,m; db ans;
typedef pair<db,int> event; #define mkp(a,b) make_pair(a,b) #define ft first #define sd second
event evt[V<<1]; db dist[V][V];
inline bool cmp(event p,event q){return p.ft<q.ft;}
inline void adjust(db &x){x=x>pi?x-pi*2:x<-pi?x+pi*2:x;}
inline bool judge(int id,db r) { int cur=id<=n,cnt=0,ret=0; for (int i=1;i<=n+m;++i) if (i!=id) { db d=dist[i][id]; if (sgn(d-2.*r)>0) continue; db alpha=acosl(d/(2.*r))-1e-30*(i>n),mid=(pts[i]-pts[id]).arg(); db st=mid-alpha,en=mid+alpha; adjust(st),adjust(en); int cst=i<=n?1:ERROR; cur+=(sgn(en-st)<0)*cst,evt[++cnt]=mkp(st,cst),evt[++cnt]=mkp(en,-cst); } ret=cur,sort(evt+1,evt+1+cnt,cmp); for (int i=1;i<=cnt;++i) ret=max(ret,cur+=evt[i].sd); return ret>=1; }
inline void binary_search(int id) { db l=ans,r=ans; for (;judge(id,r)&&r<=INF;r*=2); for (db mid;sgn(r-l)>=0;) { mid=(l+r)*.5; if (judge(id,mid)) l=(ans=mid)+EPS; else r=mid-EPS; } }
int main() { freopen("circle.in","r",stdin),freopen("circle.out","w",stdout); n=read(),m=read(); for (int i=1,x,y;i<=n+m;++i) x=read(),y=read(),pts[i]=P(x,y); random_shuffle(pts+1,pts+1+n),random_shuffle(pts+1+n,pts+1+n+m); for (int i=1;i<=n+m;++i) for (int j=1;j<=n+m;++j) dist[i][j]=(pts[i]-pts[j]).mod(); ans=1.; for (int i=1;i<=n;++i) { if (!judge(i,ans)) continue; binary_search(i); } for (int i=n+1;i<=n+m;++i) { if (!judge(i,ans)) continue; binary_search(i); } if (ans<INF*.5) printf("%.10lf\n",(double)ans); else printf("-1\n"); fclose(stdin),fclose(stdout); return 0; }
|