POJ3907:Build Your Home——题解

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

 

以上是关于POJ3907: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(线段树+离散化+扫描线)

(c)2006-2024 SYSTEM All Rights Reserved IT常识