1. 程式人生 > >POJ3907:Build Your Home——題解

POJ3907:Build Your Home——題解

das main def body scanf fabs poj round ash

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

POJ3907:Build Your Home——題解