模板:
#include<bits/stdc++.h>
#define inf 1000000000
#define ll long long
using namespace std;
int n,top;
double ans;
struct node
{
int x,y;
}p[5005],s[5005];
node operator-(node a,node b)
{
node t;t.x=a.x-b.x;t.y=a.y-b.y;return t;
}
ll operator*(node a,node b)
{
return a.x*b.y-a.y*b.x;
}
ll dis(node a,node b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
bool operator<(node a,node b)
{
ll t=(a-p[1])*(b-p[1]);
if(t==0)return dis(p[1],a)<dis(p[1],b);
return t>0;
}
double area(node a,node b,node c)
{
return fabs(a.x*b.y+a.y*c.x+b.x*c.y-b.y*c.x-c.y*a.x-a.y*b.x)/2;
}
void graham()
{
int t=1;
for(int i=2;i<=n;i++)
if(p[i].y<p[t].y||(p[i].y==p[t].y&&p[i].x<p[t].x))t=i;
swap(p[1],p[t]);
sort(p+2,p+n+1);
s[++top]=p[1];s[++top]=p[2];
for(int i=3;i<=n;i++)
{
while((s[top]-s[top-1])*(p[i]-s[top-1])<=0)top--;
s[++top]=p[i];
}
//for(int i=1;i<=top;i++)//顺时针输出,弄一个栈可以逆序输出
// printf("(%d %d)\n",s[i].x,s[i].y);
}
double getarea()///计算面积
{
double Area=0;
for(int i=2;i<=top-1;i++)
Area+=area(s[1],s[i],s[i+1]);
return Area;
}
double getl()///计算周长
{
s[top+1]=p[1];//连一个原点连一个环
for(int i=1;i<=top;i++)
ans+=sqrt(dis(s[i],s[i+1]));
printf("%.2f\n",ans);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
graham();
return 0;
}