这题其实是一个简单的模板题,可我就纠结了好久!哎
/*
这题就是凸包模板加多边形面积模板!
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=10005;
int n;
struct point
{
double x;
double y;
double there;
} p[maxn],chs[maxn];
bool cmp1(point a,point b)
{
if(a.y==b.y)
return a.x<b.x;
else
return a.y<b.y;
}
bool cmp2(point a,point b)//极角排序
{
if(a.there==b.there)
{
return a.x<b.x;
}
return a.there<b.there;
}
double get_there(point a,point b)//利用数学公式求极角
{
return atan2((a.y-b.y),(a.x-b.x));
}
bool line_point1(point a,point b,point c)
{
double m;
m=(b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
if(m>0)return false;
if(m<0)return true;
if(m==0)return true;
return false;
}
double get_point2(point chs[],int top)//求多边形面积,
{
double sum=0;
for(int i=0; i<top-1; i++)
{
sum+=(chs[i].x*chs[(i+1)%top].y-chs[i].y*chs[(i+1)%top].x);
}
sum+=chs[top-1].x*chs[0].y-chs[top-1].y*chs[0].x;
return fabs(sum/2.0);
}
int main()
{
int i;
while(scanf("%d",&n)!=EOF)
{
for(i=0; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
sort(p, p+n, cmp1);//找右下角的基点
for(i=0; i<n ; i++)
{
p[i].there=get_there(p[i],p[0]);//求极角
}
sort(p+1, p+n, cmp2);//极角排序
chs[0]=p[0];
chs[1]=p[1];
chs[2]=p[2];
int top=2;
for(i=3; i<n; i++)
{
while(top>=1&&line_point1(chs[top-1],chs[top],p[i]))
{
top--;
}
chs[++top]=p[i];
}
top++;
double ans;
ans=get_point2(chs,top);
printf("%.0lf\n",floor(ans/50.0));//foolr函数就是向下取整,和四舍五入不同,这里一开始没有这样写,直接是第一组数据152,写一下就过了,原因是羊不能只放半只,如果放不下一只,就舍去这一只!向下取整
}
return 0;
}