分析:
凸包模板 G r a h a m Graham Graham算法 复杂度 O ( n l o g n ) O(nlogn) O(nlogn) 极点存在 a 1 a_1 a1
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#include<cmath>
#define reg register
using namespace std;
typedef long long ll;
const int N=1e5+5;
struct node{
double x,y;
}a[N],p[N];
stack<int> st;
int n;
double ans;
double m(node a,node b,node c){return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);}
double dis(node a,node b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
bool cmp(node p,node p2)
{
double res=m(p,p2,a[1]);
if(res>0) return 1;
if(res==0&&dis(a[1],p)<dis(a[1],p2)) return 1;
return 0;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
if(i>1&&a[i].y<a[1].y||a[i].y==a[1].y&&a[i].x<a[1].x)
swap(a[i],a[1]);
}
sort(a+2,a+n+1,cmp);
st.push(1);
p[st.top()]=a[st.top()];
int tot=1;
for(int i=2;i<=n;i++)
{
while(st.top()>1&&m(p[st.top()],a[i],p[st.top()-1])<=0) st.pop(),tot--;
tot++;
st.push(tot);
p[st.top()]=a[i];
}
p[st.top()+1]=a[1];
for(int i=1;i<=st.size();i++)
ans+=dis(p[i],p[i+1]);
printf("%.2lf",ans);
return 0;
}