【题目大意】 有若干个多边形(不一定是凸包),按顺序给出它的顶点。求这些多边形的面积(四舍五入)。
板题。
#include<bits/stdc++.h>
using namespace std;
struct point{
double x,y;
point(double _x=0,double _y=0){x=_x,y=_y;}
friend inline double operator *(const point &a,const point &b){
return a.x*b.y-b.x*a.y;
}
}p[23333];
int k;
int main(){
while(scanf("%d",&k)==1&&k){
double ans=0;
for(int i=1;i<=k;++i)
scanf("%lf%lf",&p[i].x,&p[i].y);
p[k+1]=p[1];
for(int i=1;i<=k;++i){
ans+=p[i+1]*p[i];
}
cout<<int(fabs(ans/2)+0.5)<<'\n';
}
}