Kattis - convexpolygonarea 【数学】

这里写图片描述

题意

给出一系列点,求这个多边形面积

思路
向量叉积

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>

using namespace std;
typedef long long LL;

const double PI  = 3.14159265358979323846264338327;
const double E   = 2.718281828459;
const double eps = 1e-6;

const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e2 + 5;
const int MOD  = 1e9 + 7;

struct Node
{
    double x;
    double y;
}G[maxn];

double Cross(Node a, Node b)
{
    return a.x * b.y - a.y * b.x;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        for (int i = 0; i < n; i++)
            scanf("%lf%lf", &G[i].x, &G[i].y);
        double sum = 0;
        G[n].x = G[0].x;
        G[n].y = G[0].y;
        for (int i = 0; i < n; i++)
            sum += Cross(G[i], G[i + 1]);
        sum = sum / 2.0;
        cout << sum << endl;
    }
} 



posted @ 2018-03-11 21:55  Dup4  阅读(160)  评论(0编辑  收藏  举报