www.acmicpc.net/problem/2166

 

2166번: 다각형의 면적

첫째 줄에 N이 주어진다. 다음 N개의 줄에는 다각형을 이루는 순서대로 N개의 점의 x, y좌표가 주어진다. 좌표값은 절댓값이 100,000을 넘지 않는 정수이다.

www.acmicpc.net

수학 문제라서 풀이 나중에 씀

더보기
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

struct p {
    long long x, y;
};

int main()
{
    int n;
    cin >> n;
    vector<p> arr(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> arr[i].x >> arr[i].y;
    }

    unsigned long long s = (arr[1].x + arr[n].x) * (arr[n].y - arr[1].y);
    for (int i = 1; i < n; i++) {
        s += (arr[i].x + arr[i + 1].x) * (arr[i].y - arr[i + 1].y);
    }
    double dap = (double)llabs(s) * 0.5;
    printf("%.1lf\n", dap);
    return 0;
}