Cod sursa(job #2386402)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 22 martie 2019 19:22:33
Problema Infasuratoare convexa Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.18 kb
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
const int MAX_N = 120005;
const double EPS = 1e-12;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
int n;
pair<double, double> v[MAX_N];
bool vis[MAX_N];
int st[MAX_N], head;
double cross_product(pair<double, double> O, pair<double, double> A, pair<double, double> B)
{
    return (A.x - O.x) * (B.y - O.y) - (B.x - O.x) * (A.y - O.y);
}
int main()
{
    f >> n;
    for (int i = 1; i <= n; ++i)
        f >> v[i].x >> v[i].y;
    sort(v + 1, v + n + 1);
    st[1] = 1; st[2] = 2; head = 2;
    vis[2] = true;
    for (int i = 1, p = 1; i > 0; )
    {
        if (vis[i])
            continue;
        while (head >= 2 && cross_product(v[st[head - 1]], v[st[head]], v[i]) < EPS)
            vis[st[head--]] = false;
        st[++head] = i;
        vis[i] = true;
        int pp;
        if(i == n)
            pp = -p;
        else
            pp = p;
        if(pp == p)
            ++i;
    }
    g << head - 1 << '\n';
    g << setprecision(6) << fixed;
    for (int i = 1; i < head; ++i)
        g << v[st[i]].x << " " << v[st[i]].y << '\n';
    return 0;
}