Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- class point {
- public:
- int x, y;
- void read() {
- cin >> x >> y;
- }
- point operator - (const point &p) const {
- return point{x - p.x, y - p.y};
- }
- void operator -= (const point &p) {
- x -= p.x, y -= p.y;
- }
- int operator * (const point &p) const {
- return x * p.y - p.x * y;
- }
- int crossP(const point &A, const point &B) const {
- return (A - *this) * (B - *this);
- }
- bool operator < (const point &A) const {
- return make_pair(x, y) < make_pair(A.x, A.y);
- }
- };
- void test_case() {
- int N;
- cin >> N;
- vector<point> points(N);
- for(point &p : points)
- p.read();
- sort(points.begin(), points.end());
- vector<point> hull;
- for(int rep = 0; rep < 2; ++rep) {
- int S = hull.size();
- for(const point &C : points) {
- while((int)hull.size() > S + 1) {
- point A = hull.end()[-2],
- B = hull.end()[-1];
- if(A.crossP(B, C) <= 0) // B la stanga lui C sau A - B - C - coliniare
- break;
- hull.pop_back(); // daca e la dreapta lui C nu face parte din convex hull
- }
- hull.emplace_back(C);
- }
- hull.pop_back();
- reverse(points.begin(), points.end());
- }
- cout << hull.size() << '\n';
- for(const point &p : hull)
- cout << p.x << ' ' << p.y << '\n';
- }
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- while(T--)
- test_case();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement