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
|
#include<bits/stdc++.h> #define re register typedef long long ll; template<class T> inline void read(T &x) { x=0; char ch=getchar(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(t) x=-x; } template<class T,class ...T1> inline void read(T &x,T1 &...x1){ read(x),read(x1...); } template<class T> inline void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } template<> inline void write(bool x){ putchar(x?'1':'0'); } template<> inline void write(char c){ putchar(c); } template<> inline void write(char *s){ while(*s!='\0') putchar(*s++); } template<> inline void write(const char *s){ while(*s!='\0') putchar(*s++); } template<class T,class ...T1> inline void write(T x,T1 ...x1){ write(x),write(x1...); } template<class T> inline bool checkMax(T &x,T y){ return x<y?x=y,1:0; } template<class T> inline bool checkMin(T &x,T y){ return x>y?x=y,1:0; } const int MAXN=2e5+10; const int INF=0x3f3f3f3f; int N; struct Point { double x,y; bool operator<(const Point &a) const { return x==a.x?y<a.y:x<a.x; } }Pt[MAXN],a[MAXN],b[MAXN]; inline double getDist(int x,int y) { return std::sqrt((Pt[x].x-Pt[y].x)*(Pt[x].x-Pt[y].x)+(Pt[x].y-Pt[y].y)*(Pt[x].y-Pt[y].y)); } inline double getDist(Point x,Point y) { return std::sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y)); } double solve(int l,int r) { if(l>=r) return INF; int mid=(l+r)>>1; double dx=(Pt[mid].x+Pt[mid+1].x)/2.0; double res=std::min(solve(l,mid),solve(mid+1,r)); int l1=l,r1=mid+1,cnt=0; for(int i=l;i<=r;++i) { if(l1<=mid&&(r1>r||Pt[l1].y<Pt[r1].y)) { a[i]=Pt[l1++]; if(dx-res/2<a[i].x) b[++cnt]=a[i]; } else { a[i]=Pt[r1++]; if(a[i].x<dx+res/2) b[++cnt]=a[i]; } } for(int i=l;i<=r;++i) Pt[i]=a[i]; for(int i=1;i<=cnt;++i) for(int j=i+1;j<=cnt;++j) { if(b[j].y-b[i].y>=res/2) break; for(int k=j+1;k<=cnt;++k) { if(b[k].y-b[j].y>=res/2) break; checkMin(res,getDist(b[i],b[j])+getDist(b[i],b[k])+getDist(b[j],b[k])); } } return res; } int main() { read(N); for(int i=1;i<=N;++i) scanf("%lf%lf",&Pt[i].x,&Pt[i].y); std::sort(Pt+1,Pt+N+1); printf("%.6lf",solve(1,N)); return 0; }
|