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

Posted MSPqwq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 3907 Build Your Home | 计算多边形面积相关的知识,希望对你有一定的参考价值。

给个多边形

计算面积

输出要四舍五入


直接用向量叉乘就好

四舍五入可以+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 | 计算多边形面积的主要内容,如果未能解决你的问题,请参考以下文章

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

[poj 2482] Stars in Your Window

POJ2482 Stars in Your Window

POJ2482 Stars in Your Window 题解

How To Build Your First Meteor App And Discover Your Inner Artist

POJ 2482 Stars in Your Window(线段树+离散化+扫描线)