diff --git a/yuyu0830/README.md b/yuyu0830/README.md index e027046..e7b64ca 100644 --- a/yuyu0830/README.md +++ b/yuyu0830/README.md @@ -15,4 +15,5 @@ | 11차시| 2024.05.08 | 그리디 | [연료 채우기](https://www.acmicpc.net/problem/1826) | - | | 12차시| 2024.05.13 | 해시 | [두 배열의 합](https://www.acmicpc.net/problem/2143) | - | | 13차시| 2024.05.21 | LIS | [가장 긴 증가하는 부분 수열 2](https://www.acmicpc.net/problem/12015) | - | +| 15차시| 2024.06.01 | 기하 | [다각형의 면적](https://www.acmicpc.net/problem/2166) | - | --- \ No newline at end of file diff --git "a/yuyu0830/\354\210\230\355\225\231/2166.cpp" "b/yuyu0830/\354\210\230\355\225\231/2166.cpp" new file mode 100644 index 0000000..e76271c --- /dev/null +++ "b/yuyu0830/\354\210\230\355\225\231/2166.cpp" @@ -0,0 +1,51 @@ +#include +#include +#define MAX 99999999 + +using namespace std; + +typedef long long ll; + +struct Point { + ll x, y; + Point(ll X, ll Y) : x(X), y(Y) {}; +}; + +ll getArea(Point a, Point b) { + ll square = abs((a.x - b.x) * min(abs(a.y), abs(b.y))) * 2; + ll triangle = abs((a.x - b.x) * (a.y - b.y)); + + return square + triangle; +} + +vector v; + +int main() { + ll a, b, area = 0, mx = MAX, my = MAX; + + int n; cin >> n; + + for (int i = 0; i < n; i++) { + cin >> a >> b; + v.push_back(Point(a, b)); + + mx = min(mx, a); + my = min(my, b); + } + + for (auto &p : v) { + p.x -= mx; + p.y -= my; + } + + v.push_back(v[0]); + + for (int i = 0; i < n; i++) { + Point cur = v[i]; + Point next = v[i + 1]; + + area += getArea(cur, next) * (cur.x <= next.x ? 1 : -1); + } + + printf("%.1f\n", abs((double) area / 2)); +} \ No newline at end of file