题目描述
思路
水题
直接算凸包面积/50,向下取整。
AC code
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e4+10;
struct node{double x,y;}p[N],h[N];
int tp,sta[N],n;bool v[N];
bool cmp(node a,node b){return a.x==b.x?a.y<b.y:a.x<b.x;}
double mul(node p1,node p2,node p0)
{
double x1=p1.x-p0.x,y1=p1.y-p0.y;
double x2=p2.x-p0.x,y2=p2.y-p0.y;
return x1*y2-x2*y1;
}
void tb()
{
tp=0;sort(p+1,p+n+1,cmp);sta[++tp]=1;
for(int i=2;i<=n;i++)
{
while(tp>1&&mul(p[sta[tp]],p[i],p[sta[tp-1]])<=0)v[sta[tp--]]=0;
sta[++tp]=i;v[i]=1;
}
int top=tp;
for(int i=n-1;i;i--)
if(!v[i])
{
while(tp>top&&mul(p[sta[tp]],p[i],p[sta[tp-1]])<=0)--tp;
sta[++tp]=i;
}
for(int i=1;i<=tp;i++)
h[i]=p[sta[i]];
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
tb();
double ans=0;
for(int i=3;i<=tp;i++)ans+=mul(h[i-1],h[i],h[1]);
ans=ans/2;
printf("%d\n",(int)(fabs(ans)/50.0));
return 0;
}