【伪原题】平面上最小三角形
好迷啊= =和平面上最接近点对做法一猫一样啊~~~
// It is made by XZZ
#include<cstdio>
#include<algorithm>
#include<cmath>
#define Fname ""
using namespace std;
#define rep(a,b,c) for(rg int a=b;a<=c;a++)
#define drep(a,b,c) for(rg int a=b;a>=c;a--)
#define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
#define il inline
#define rg register
#define vd void
#define db long double
typedef long long ll;
il int gi(){
rg int x=0;bool flg=0;rg char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')flg=1;ch=getchar();}
while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
return flg?-x:x;
}
const int maxn=2e5+2;
struct p{db x,y;}s[maxn],t[maxn];
il bool cmp1(const p&a,const p&b){return a.x<b.x;}
il bool cmp2(const p&a,const p&b){return a.y<b.y;}
il db dist(int a,int b){return sqrt((s[a].x-s[b].x)*(s[a].x-s[b].x)+(s[a].y-s[b].y)*(s[a].y-s[b].y));}
il db dist_(int a,int b){return sqrt((t[a].x-t[b].x)*(t[a].x-t[b].x)+(t[a].y-t[b].y)*(t[a].y-t[b].y));}
db ans=1e19;
int i,tot;
il vd _solve(int l,int r){
if(l>r-2)return;
if(l==r-2){ans=min(ans,dist(l,l+1)+dist(l,r)+dist(r-1,r));return;}
int mid=(l+r)>>1;
_solve(l,mid),_solve(mid+1,r);
db _mid=(s[mid+1].x+s[mid].x)*0.5;
tot=0;
i=mid;while((i^l)&&_mid-s[i].x<ans*0.5)t[++tot]=s[i],--i;
i=mid+1;while((i^r)&&s[i].x-_mid<ans*0.5)t[++tot]=s[i],++i;
sort(t+1,t+tot+1,cmp2);
i=1;
//printf("%d %.8Lf
",tot,ans);
rep(j,1,tot){
while(t[j].y-t[i].y>ans*0.5)++i;
drep(k,j-1,i)drep(g,k-1,i)ans=min(ans,dist_(j,k)+dist_(k,g)+dist_(j,g));
}
}
int main(){
freopen(Fname".in","r",stdin);
freopen(Fname".out","w",stdout);
int n=gi();
rep(i,1,n)s[i]=(p){(db)gi(),(db)gi()};
sort(s+1,s+n+1,cmp1);_solve(1,n);
printf("%.6Lf
",ans);
return 0;
}
PS.感觉我变农了~什么都想在最前面加下划线