Cod sursa(job #2280633)

Utilizator smoc_georgemarianSmoc George-Marian smoc_georgemarian Data 10 noiembrie 2018 22:18:22
Problema Infasuratoare convexa Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.1 kb
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;

ifstream cin("infasuratoare.in");
ofstream cout("infasuratoare.out");

int nr, contor;

struct Punct
{
    double x, y;
}v[120004], sol[120004];

bool f1(Punct a, Punct b)
{
    if(a.x != b.x)
    return a.x < b.x;
    return a.y < b.y;
}

double determinant(Punct a, Punct b, Punct c)
{
    return a.x*b.y+b.x*c.y+a.y*c.x-c.x*b.y-c.y*a.x-a.y*b.x;
}

bool f2(Punct a, Punct b)
{
    return determinant(v[1], a, b) < 0;
}

int main()
{
    cin >> nr;
    for(int i=1; i <= nr; i++)
    {
        cin >> v[i].x >> v[i].y;
    }

    sort(v+1, v+nr+1, f1);
    sort(v+2, v+nr+1, f2);
    sol[1] = v[1];
    sol[2] = v[2];
    sol[3] = v[3];
    contor = 3;

    for(int i=4; i <= nr; i++)
    {
        while(determinant(sol[contor-1], sol[contor], v[i]) > 0)
        contor--;

        contor++;
        sol[contor] = v[i];
    }

    cout << contor << '\n';
    for(int i=contor; i > 0; i--)
    {
        cout << fixed << setprecision(13) << sol[i].x << ' ' << sol[i].y << '\n';
    }
}