poj3348Cows 凸包板子

凸包板子

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
struct Point
{
    int x,y;
};
Point a[10010];
Point b[10010];
bool cmp(Point aa,Point bb)
{
    if(aa.x==bb.x)
    return aa.y<bb.y;
    else return aa.x<bb.x;
}
int Cross(Point aa,Point bb,Point cc)
{
    int ax=bb.x-aa.x;
    int bx=cc.x-aa.x;
    int ay=bb.y-aa.y;
    int by=cc.y-aa.y;
    if(ax*by-bx*ay<=0)return 0;
    else return ax*by-bx*ay;
}
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+n+1,cmp);
    int m=0;
    for(int i=1;i<=n;i++)
    {
        while(m>1&& !Cross(b[m-1],b[m],a[i]))m--;
        b[++m]=a[i];
    }
    int p=m;
    for(int i=n-1;i>=1;i--)
    {
        while(m>p&& !Cross(b[m-1],b[m],a[i]))m--;
        b[++m]=a[i];
    }
    long long sum=0;
    for(int i=3;i<=m;i++)
    sum+=Cross(b[1],b[i-1],b[i]);
    printf("%lld
",sum/100);
    return 0;
}
原文地址:https://www.cnblogs.com/mybing/p/13880241.html