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

 

转载于:https://www.cnblogs.com/luyouqi233/p/8051967.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值