首页 > 其他 > 详细

改革春风吹满地---hdu2036(多边形用差积求面积)

时间:2016-08-01 12:12:48      阅读:213      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2036

 

技术分享

 

技术分享
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

#define met(a, b) memset(a, b, sizeof(a))
#define N 111

typedef long long LL;

struct point
{
    int x, y;

    point(){}
    point(int x, int y):x(x), y(y) {}

    friend int operator ^(point p, point q)
    {
        return p.x*q.y-p.y*q.x;
    };

}p[N];

int main()
{
    int n;

    while(scanf("%d", &n), n)
    {
        for(int i=1; i<=n; i++)
            scanf("%d %d", &p[i].x, &p[i].y);
        p[0] = p[n];

        int  S = 0;

        for(int i=1; i<=n; i++)
        {
            S += p[i]^p[i-1];
        }
        printf("%.1f\n", abs(S)/2.0);
    }
    return 0;
}
View Code

 

改革春风吹满地---hdu2036(多边形用差积求面积)

原文:http://www.cnblogs.com/zhengguiping--9876/p/5724884.html

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