Skip to content

Commit

Permalink
15-yuyu0830
Browse files Browse the repository at this point in the history
15-yuyu0830
  • Loading branch information
yuyu0830 authored Jul 4, 2024
2 parents bf67c33 + a98e8e2 commit 5600fa0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) | - |
---
51 changes: 51 additions & 0 deletions yuyu0830/μˆ˜ν•™/2166.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <iostream>
#include <vector>
#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<Point> 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));
}

0 comments on commit 5600fa0

Please sign in to comment.