Cod sursa(job #2883497)

Utilizator MocalinnoMoca Andrei Catalin Mocalinno Data 1 aprilie 2022 16:04:40
Problema Infasuratoare convexa Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.16 kb
#include <bits/stdc++.h>
using namespace std;

string const& task("infasuratoare");
ifstream fin(task + ".in");
ofstream fout(task + ".out");

using LD = long double;
const int N(12e4 + 5);

struct Point {
    LD x, y;
};

Point st[N], v[N];
int n, k;

inline LD Det(Point const& a, Point const& b, Point const& c) {
    return ((a.x * b.y + a.y * c.x + b.x * c.y) - (b.y * c.x + a.y * b.x + a.x * c.y));
}
inline bool CmpY(Point const& a, Point const& b) {
    return a.y < b.y;
}
inline bool Cmp(Point const& a, Point const& b) {
    return (Det(v[1], a, b) > 0.0);
}

inline void Insert(Point const& p) {
    while (k > 1 && Det(st[k - 1], st[k], p) <= 0.0)
        --k;
    st[++k] = p;
}

signed main() {
    fin >> n;
    for (int i = 1; i <= n; ++i)
        fin >> v[i].x >> v[i].y;
    sort(v + 1, v + n + 1, CmpY);
    sort(v + 2, v + n + 1, Cmp);
    st[++k] = v[1];
    st[++k] = v[2];
    for (int i = 3; i <= n; ++i)
        Insert(v[i]);
    Insert(v[1]);
    fout << --k << '\n';
    fout << fixed << setprecision(12);
    for (int i = 1; i <= k; ++i)
        fout << st[i].x << ' ' << st[i].y << '\n';

    return 0;
}