思路:
凸包板题
c o d e code code
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long n, top, s[1000010];
double ans;
struct node
{
double x, y;
}p[1000010];
double cj(double x, double y, double x1, double y1, double x2, double y2)
{
return (x1-x)*(y2-y)-(x2-x)*(y1-y);
}
double dis(double x, double y, double x1, double y1)
{
return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
}
bool cmp(node x, node y)
{
double o=cj(p[1].x, p[1].y, x.x, x.y, y.x, y.y);
if(o>0)
return 1;
if(o==0&&dis(x.x, x.y, p[1].x, p[1].y)<dis(y.x, y.y, p[1].x, p[1].y))
return 1;
return 0;
}
double js(double x, double y, double x1, double y1)
{
return x*y1-y*x1;
}
int main()
{
scanf("%lld", &n);
for(long long i=1; i<=n; i++)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
if(i!=1&&p[i].y<p[1].y)
{
swap(p[i].x, p[1].x);
swap(p[i].y, p[1].y);
}
else if(i!=1&&p[i].y==p[1].y&&p[i].x<p[1].x)
{
swap(p[i].x, p[1].x);
swap(p[i].y, p[1].y);
}
}
sort(p+2, p+1+n, cmp);
s[1]=1, top=1;
for(long long i=2; i<=n; i++)
{
while(top>1&&cj(p[s[top-1]].x, p[s[top-1]].y, p[s[top]].x, p[s[top]].y, p[i].x, p[i].y)<=0)
top--;
s[++top]=i;
}
s[top+1]=1;
for(long long i=1; i<=top; i++)
ans+=js(p[s[i]].x, p[s[i]].y, p[s[i+1]].x, p[s[i+1]].y);
int ans1=ans/100;
printf("%d", ans1);
return 0;
}