/*
ID:BLACK-WOOD
LANG:C++
TASK:fc
*/
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define esp 1e-8
#define MAXN 10010
using namespace std;
struct point
{
double x,y;
point(double _x = 0,double _y = 0) : x(_x),y(_y) {}
void input() { scanf("%lf %lf",&x,&y); }
};
double sgn(double d)
{ return d > esp ? 1 : ( d < -esp ? -1 : 0 ) ;
}
point operator-(const point p1, const point p2)
{ return point(p1.x - p2.x, p1.y - p2.y);
}
double operator*(const point p1, const point p2)
{ return p1.x*p2.y - p1.y*p2.x;
}
double operator<(const point p1, const point p2)
{ if( sgn(p1.x - p2.x) != 0 ) return p1.x < p2.x ;
else return sgn( p1.y - p2.y ) < 0;
}
int n,tn;
point a[MAXN],tu[MAXN];
void init()
{
int i,j,k,r,w;
scanf("%d",&n);
for(i=1;i<=n;i++)
a[i].input();
}
void tubao()
{
point hu[MAXN],hd[MAXN];
int i,j,k,r,w,un,dn;
sort(a+1,a+n+1);
hu[1] = hd[1] = a[1];
hu[2] = hd[2] = a[2];
un = dn = 2;
for(i=3;i<=n;i++)
{ for(; un > 1 && sgn( (hu[un] - hu[un-1]) * (a[i] - hu[un]) ) <= 0 ; un--);
for(; dn > 1 && sgn( (hd[dn] - hd[dn-1]) * (a[i] - hd[dn]) ) >= 0 ; dn--);
hu[++un] = a[i];
hd[++dn] = a[i];
}
tn = 0;
for(i=1;i<=un-1;i++) tu[++tn] = hu[i];
for(i=dn;i>=2;i--) tu[++tn] = hd[i];
}
void getans()
{
int i,j,k;
double ans=0;
tu[0] = tu[tn];
for(i=1;i<=tn;i++)
{ ans += sqrt( (tu[i].x-tu[i-1].x)*(tu[i].x-tu[i-1].x) + (tu[i].y-tu[i-1].y)*(tu[i].y-tu[i-1].y) );
}
printf("%0.2f\n",ans);
}
int main()
{
freopen("fc.in","r",stdin);
freopen("fc.out","w",stdout);
init();
tubao();
getans();
return 0;
}
凸包
最新推荐文章于 2024-06-25 16:19:07 发布