凸包,勿忘


#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;

typedef long long ll;
const double eps=1e-10;
int dcpm(double a)
{
    if(fabs(a)<eps)
        return 0;
    else
        return a<0 ? -1:1;
}
struct stu
{
    double x,y;
    stu():x(0),y(0){}
    stu(double a,double b):x(a),y(b){}
    bool operator < (const stu &b)const
    {
        if(x==b.x)
            return y<b.y;
        return x<b.x;
    }
    stu operator - (const stu &b )
    {
        return stu(x-b.x,y-b.y);
    }
}q[1005],p[1005];
double det(stu a,stu b)
{
    return a.x*b.y-a.y*b.x;
}
int andrew(stu *a,stu *b,int n)
{
    sort(a,a+n);
    int len=0;
    for(int i=0; i<n; i++)
    {
        while(len>1&&det(b[len-1]-b[len-2],a[i]-b[len-2])<=0)
            len--;
        b[len++]=a[i];
    }
    int m=len;
    for(int i=n-2; i>=0; i--)
    {
        while(len>m&&det(b[len-1]-b[len-2],a[i]-b[len-2])<=0)
            len--;
        b[len++]=a[i];
    }
    if(len>1) len--;
    return len;
}
double PolygonArea(stu *p,int n)
{
    double area =0;
    for(int i=1; i<n-1; i++)
    {
        area +=det(p[i]-p[0],p[i+1]-p[0]);
    }
    return fabs(area)/2;
}
int main()
{
    int a,m;
    scanf("%d",&a);
    for(int i=0; i<a; i++)
        scanf("%lf %lf",&q[i].x,&q[i].y);
    m=andrew(q,p,a);
    double n=PolygonArea(p,m);
    int w=floor(n/50);
    printf("%d\n",w);
}

猜你喜欢

转载自blog.csdn.net/qq_41081096/article/details/81227057