#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n,top;
double len;
struct point{
double x,y;
point operator - (point&s){
return (point){x-s.x,y-s.y};
}
}a[10005];
int p[10005];
double operator * (point a,point b){
return a.x*b.y-a.y*b.x;
}
double dist(point p1,point p2){
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
bool judge(point p0,point p1,point p2)
{
double s=(p1-p0)*(p2-p0);
return s<0||(s==0&&dist(p0,p1)>dist(p0,p2));
}
int main()
{
scanf("%d",&n);
int firsts=1;
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
if(a[i].x<a[firsts].x||a[i].x==a[firsts].x&&a[i].y<a[firsts].y)
firsts=i;
}
p[++top]=firsts;
do{
int ep=1;
for(int i=2;i<=n;i++)
if(judge(a[p[top]],a[i],a[ep]))
ep=i;
len+=sqrt(dist(a[ep],a[p[top]]));
p[++top]=ep;
}while(p[top]!=firsts);
printf("%.2f",len);
return 0;
}
二维凸包
最新推荐文章于 2023-09-18 01:23:34 发布