X-man

导航

poj 3348 Cows

#include<stdio.h>
#include<algorithm>
using namespace std;
#define Max 10100
struct Point
{
    int x,y;
}p[Max];
int dis(Point p1,Point p2)
{
    return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
int xmult(Point p1,Point p2,Point p0)
{
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
bool cmp(Point p1,Point p2)
{
    int tmp=xmult(p1,p2,p[0]);
    if(tmp>0||!tmp&&dis(p1,p[0])<dis(p2,p[0]))
    return true;
    return false;
}

int Graham(Point *p,int n)
{
    sort(p+1,p+n,cmp);
    int i,top=1;
    for(i=2;i<n;i++)
    {
        while(xmult(p[top],p[i],p[top-1])<=0)
        top--;
        top++;
        p[top]=p[i];
    }
    return top+1;
}
double cal(Point *p,int n)
{
    int i,j;
    double ans=0;
    for(i=1;i<n-1;i++)
    {
        ans+=xmult(p[i],p[i+1],p[0]);
    }
    return ans/2/50;
}
int main()
{
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&p[i].x,&p[i].y);
        if(p[i].y<p[0].y||p[i].y==p[0].y&&p[i].x<p[0].x)
            swap(p[i],p[0]);
    }
    n=Graham(p,n);
    int ans=cal(p,n);
    printf("%d\n",ans);
    return 0;
}

 

posted on 2013-08-04 15:51  雨钝风轻  阅读(136)  评论(0编辑  收藏  举报