poj 3907 Build Your Home 多边形面积

2015-07-20 17:07:34 ? 作者: ? 浏览: 3

题意:

给一个多边形,求它的面积。

分析:

算一遍叉积即可。

代码:

?

//poj 3907
//sep9
#include 
  
   
#include 
   
     using namespace std; int main() { float x0,y0,x1,y1; short n; while(scanf("%hd",&n)==1&&n){ float sum=0; scanf("%f%f",&x0,&y0); float xx=x0,yy=y0; n--; while(n--){ scanf("%f%f",&x1,&y1); sum+=x0*y1-x1*y0; x0=x1; y0=y1; } x1=xx; y1=yy; sum+=x0*y1-x1*y0; printf("%.0f\n",fabs(sum)/2+1e-6); } return 0; } 
   
  


?

-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: