1. 程式人生 > >【多邊形面積】 POJ 3907

【多邊形面積】 POJ 3907

鐵爐堡傳送門

【題目大意】 有若干個多邊形(不一定是凸包),按順序給出它的頂點。求這些多邊形的面積(四捨五入)。

板題。

#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';
	}
}