Cod sursa(job #3284714)

Utilizator 1gbr1Gabara 1gbr1 Data 12 martie 2025 09:22:19
Problema Infasuratoare convexa Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.5 kb
#include <vector>
#include <fstream>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;

ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
int n;

struct da {
    double x, y;
    bool operator < (const da& other)const
    {
        if (this->y == other.y)
            return this->x < other.x;
        return this->y < other.y;
    }
};
da a[120004];
int st[120004];
bitset<120005> fr;
bool isleft(da a, da b, da c)
{
    return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x) > 0;
}
int main()
{
    fin >> n;
    for (int i = 1; i <= n; i++)
        fin >> a[i].x >> a[i].y;
    sort(a + 1, a + n + 1);
    st[1] = 1;
    st[2] = 2;
    fr[1] = 1;
    fr[2] = 1;
    int top = 2;
    cout << "DA";
    for (int i = 3; i <= n; i++)
    {
        while (top >= 2 && !isleft(a[st[top - 1]], a[st[top]], a[i]))
        {
            fr[st[top]] = 0;
            top--;
        }
        st[++top] = i;
        fr[i] = 1;
    }
    fr[1] = 0;
    for (int i = n; i >= 1; i--)
    {
        if (!fr[i])
        {
            while (top >= 2 && !isleft(a[st[top - 1]], a[st[top]], a[i]))
            {
                fr[st[top]] = 0;
                top--;
            }
        }
        fr[i] = 1;
        st[++top] = i;
    }
    fout << top - 1 << "\n";
    for (int i = 1; i < top; i++)
        fout << fixed << setprecision(6) << a[st[i]].x << " " << a[st[i]].y << "\n";
    return 0;
}