코딩테스트/백준

[골5] 2166 - 다각형의 면적

ShovelingLife 2023. 9. 26. 15:20
#include <iostream>
#include <vector>
#include <cmath>

#define FAST_IO() \
{\
	ios::sync_with_stdio(false);\
	cin.tie(NULL); \
	cout.tie(NULL); \
}\

#define x first
#define y second

using namespace std;

using dp = pair<double, double>;

double Calculate(double x1, double x2, double x3, double y1, double y2, double y3)
{
	double res = x1 * y2 + x2 * y3 + x3 * y1;
	res -= x2 * y1 + x3 * y2 + x1 * y3;
	return res / 2;
}

int main()
{
	FAST_IO();
	int n;
	cin >> n;

	vector<dp> v(n);

	for (int i = 0; i < n; i++)
		cin >> v[i].x >> v[i].y;

	double res = 0;
	
	for (int i = 1; i < n; i++)
		res += Calculate(v[0].x, v[i - 1].x, v[i].x, v[0].y, v[i - 1].y, v[i].y);

	cout << fixed;
	cout.precision(1);
	cout << abs(res);
	return 0;
}