# JZOJ4033. 【GCJ2009B】Min Perimeter

4
0 0
2 0
0 2
2 2

6.828427124746

0 < n<=100000

## code

``````#include <queue>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <time.h>
#define ll long long
#define N 100003
#define M 103
#define db double
#define P putchar
#define G getchar
#define inf 998244353
#define pi 3.1415926535897932384626433832795
using namespace std;
char ch;
{
n=0;
ch=G();
while((ch<'0' || ch>'9') && ch!='-')ch=G();
ll w=1;
if(ch=='-')w=-1,ch=G();
while('0'<=ch && ch<='9')n=(n<<3) (n<<1) ch-'0',ch=G();
n*=w;
}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
ll abs(ll x){return x<0?-x:x;}
ll sqr(ll x){return x*x;}
void write(ll x){if(x>9) write(x/10);P(x%10 '0');}
struct node
{
ll x,y;
}a[N],b[N];
db dis(node a,node b)
{
return sqrt((db)(a.x-b.x)*(a.x-b.x) (a.y-b.y)*(a.y-b.y));
}
db get(node a,node b,node c)
{
return dis(a,b) dis(a,c) dis(b,c);
}
bool cmp(node a,node b)
{
return a.x<b.x;
}
bool cmp1(node a,node b)
{
return a.y<b.y;
}
ll n;
db solve(int l,int r)
{
int m=(l r)>>1;
db mi=2147483647;
if(r-l<2)return mi;
mi=min(solve(l,m),solve(m 1,r));
db t=mi/2,w=a[m].x;
int st,fi;
for(st=m;st>=l && w-a[st].x<=t;st--);
for(fi=m;fi<=r && a[fi].x-w<=t;fi  );
for(int i=st 1;i<fi;i  )b[i-st]=a[i];
int p=fi-st-1;
sort(b 1,b 1 p,cmp1);
int id=1;
for(int i=1;i<=p;i  )
{
for(int j=id;j<i;j  )
for(int k=j 1;k<i;k  )
mi=min(mi,get(b[i],b[j],b[k]));
for(t=mi/2;b[i].y-b[id].y>t && id<i;id  );
}
return mi;
}
int main()
{
for(int i=1;i<=n;i  )
sort(a 1,a 1 n,cmp);
printf("%.10lf",solve(1,n));
return 0;
}
``````