-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcses_2191.cpp
More file actions
54 lines (49 loc) · 1011 Bytes
/
cses_2191.cpp
File metadata and controls
54 lines (49 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/extc++.h>
using namespace std;
#define double long long
struct PT
{
double x, y;
PT(double x = 0, double y = 0) : x(x), y(y) {}
PT operator+(const PT &b) const
{
return PT(x + b.x, y + b.y);
}
PT operator-(const PT &b) const
{
return PT(x - b.x, y - b.y);
}
double dot(const PT &b) const
{
return x * b.x + y * b.y;
}
double cross(const PT &b) const
{
return x * b.y - y * b.x;
}
};
double area(const vector<PT> &Polygon)
{
if (Polygon.size() <= 1)
return 0;
double ans = 0;
for (auto a = --Polygon.end(), b = Polygon.begin(); b != Polygon.end(); a = b++)
ans += a->cross(*b);
return abs(ans);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<PT> poly(n);
for (int i = 0; i < n; i++)
{
int64_t x, y;
cin >> x >> y;
poly[i] = PT(x, y);
}
cout << area(poly) << '\n';
return 0;
}