首页 > 其他 > 详细

POJ 3907 Build Your Home | 计算多边形面积

时间:2017-12-07 16:56:07      阅读:183      评论:0      收藏:0      [点我收藏+]

给个多边形

计算面积

输出要四舍五入


直接用向量叉乘就好

四舍五入可以+0.5向下取整

#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 10005
#define eps 1e-8
using namespace std;
struct point
{
    double x,y;
    inline double operator *(const point &rhs) const
	{
	    return x*rhs.y-y*rhs.x;
	}
}po[N];
int n;
double S;
double abs(double x)
{
    return x>0?x:-x;
}
double calc()
{
    double ret=0;
    for (int i=1;i<=n;i++)
	ret+=po[i]*po[i+1];
    return abs(ret/2)+0.5;
}
int main()
{
    while (scanf("%d",&n)!=EOF && n)
    {
	for (int i=1;i<=n;i++)
	    scanf("%lf%lf",&po[i].x,&po[i].y);
	po[n+1]=po[1];
	printf("%d\n",(int)calc());
    }
    return 0;
}

 

POJ 3907 Build Your Home | 计算多边形面积

原文:http://www.cnblogs.com/mrsheep/p/7999544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!