POJ3907:Build Your Home——题解
http://poj.org/problem?id=3907
题目大意:求多边形面积,结果四舍五入。
————————————————————
多边形面积公式板子题。
#include<cstdio> #include<queue> #include<cmath> #include<cstring> #include<vector> #include<algorithm> using namespace std; const int K=1e4+5; typedef double dl; struct point{//既是向量又是点 dl x; dl y; }q[K]; int n; inline point getmag(point a,point b){ point s; s.x=b.x-a.x;s.y=b.y-a.y; return s; } inline dl multiX(point a,point b){ return a.x*b.y-b.x*a.y; } inline dl area(){ dl ans=0; for(int i=1;i<=n;i++){ ans+=multiX(getmag(q[0],q[i]),getmag(q[0],q[i%n+1])); } return fabs(ans)/2; } int main(){ q[0].x=0,q[0].y=0; while(scanf("%d",&n)!=EOF&&n){ for(int i=1;i<=n;i++){ scanf("%lf%lf",&q[i].x,&q[i].y); } printf("%d\n",(int)round(area())); } return 0; }