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
| #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #define ll long long #define ld long double using namespace std; namespace Ehnaev{ inline ll read() { ll ret=0,f=1;char ch=getchar(); while(ch<48||ch>57) {if(ch==45) f=-f;ch=getchar();} while(ch>=48&&ch<=57) {ret=(ret<<3)+(ret<<1)+ch-48;ch=getchar();} return ret*f; } inline void write(ll x) { static char buf[22];static ll len=-1; if(x>=0) {do{buf[++len]=x%10+48;x/=10;}while(x);} else {putchar(45);do{buf[++len]=-(x%10)+48;x/=10;}while(x);} while(len>=0) putchar(buf[len--]); } }using Ehnaev::read;using Ehnaev::write;
const ll N=2e6; const ld inf=2e18;
ll n; ld ans=inf; ll d[N+5],lc[N+5],rc[N+5]; ld L[N+5],R[N+5],D[N+5],U[N+5];
struct node{ld x,y;}a[N+5];
inline ld Dist(ll u,ll v) { return (a[u].x-a[v].x)*(a[u].x-a[v].x)+(a[u].y-a[v].y)*(a[u].y-a[v].y); }
inline bool Cmp1(node a,node b) {return a.x<b.x;} inline bool Cmp2(node a,node b) {return a.y<b.y;}
inline void Maintain(ll x) { L[x]=R[x]=a[x].x;D[x]=U[x]=a[x].y; if(lc[x]) { L[x]=min(L[x],L[lc[x]]);R[x]=max(R[x],R[lc[x]]); D[x]=min(D[x],D[lc[x]]);U[x]=max(U[x],U[lc[x]]); } if(rc[x]) { L[x]=min(L[x],L[rc[x]]);R[x]=max(R[x],R[rc[x]]); D[x]=min(D[x],D[rc[x]]);U[x]=max(U[x],U[rc[x]]); } }
inline ll Build(ll l,ll r) { if(l>=r) return 0;ll mid=(l+r)>>1; ld avx=0,avy=0,vax=0,vay=0; for(ll i=l;i<=r;i++) {avx+=a[i].x;avy+=a[i].y;} avx/=(ld)(r-l+1);avy/=(ld)(r-l+1); for(ll i=l;i<=r;i++) { vax+=(a[i].x-avx)*(a[i].x-avx);vay+=(a[i].y-avy)*(a[i].y-avy); } if(vax>=vay) {d[mid]=1;nth_element(a+l,a+mid,a+r+1,Cmp1);} else {d[mid]=2;nth_element(a+l,a+mid,a+r+1,Cmp2);} lc[mid]=Build(l,mid-1);rc[mid]=Build(mid+1,r); Maintain(mid);return mid; }
inline ld F(ll u,ll v) { ld ret=0; if(L[v]>a[u].x) ret+=(L[v]-a[u].x)*(L[v]-a[u].x); if(R[v]<a[u].x) ret+=(a[u].x-R[v])*(a[u].x-R[v]); if(D[v]>a[u].y) ret+=(D[v]-a[u].y)*(D[v]-a[u].y); if(U[v]<a[u].y) ret+=(a[u].y-U[v])*(a[u].y-U[v]); return ret; }
inline void Query(ll l,ll r,ll x) { if(l>r) return;ll mid=(l+r)>>1; if(mid!=x) ans=min(ans,Dist(x,mid)); if(l==r) return;ld distl=F(x,lc[mid]),distr=F(x,rc[mid]); if(distl<ans&&distr<ans) { if(distl<distr) { Query(l,mid-1,x);if(distr<ans) Query(mid+1,r,x); } else { Query(mid+1,r,x);if(distl<ans) Query(l,mid-1,x); } } else { if(distl<ans) Query(l,mid-1,x);if(distr<ans) Query(mid+1,r,x); } }
int main() {
n=read();
for(ll i=1;i<=n;i++) scanf("%Lf %Lf",&a[i].x,&a[i].y);
Build(1,n);
for(ll i=1;i<=n;i++) Query(1,n,i);
printf("%.4Lf",sqrt(ans));
return 0; }
|