Cod sursa(job #1641978)

Utilizator KrosomAngelo Barbu Krosom Data 9 martie 2016 11:52:19
Problema Infasuratoare convexa Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.13 kb
#include <bits/stdc++.h>
#define nmax 120001
#define eps 1e-12
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
struct punct
    {
        double x, y;
    }v[nmax];
bool cmp(punct a, punct b)
{
    if (a.x>b.x)
        return true;
        else
        if (a.x==b.x)
            return (a.y<b.y);

                return false;
}
int det (punct a, punct b, punct c)
{
    return (a.x*b.y+b.x*c.y+a.y*c.x-b.y*c.x-a.x*c.y-a.y*b.x)<eps;
}
int n, st[nmax], k, viz[nmax];
int main()
{
    int i, mod=1;
    f>>n;
    for (i=1; i<=n; i++)
        {
            f>>v[i].x;
            f>>v[i].y;
        }
    sort (v+1, v+n+1, cmp);
    st[++k]=1;
    st[++k]=2;
    viz[2]=1;
    for (i=3; i>0; i+=mod)
        if (!viz[i])
    {
        while (k>1 && det(v[st[k-1]], v[st[k]], v[i]))
            viz[st[k--]]=0;
        st[++k]=i;
        viz[i]=1;
        if (i==n)
            mod=-1;
    }
    g<<k-1<<'\n';
    for (i=1; i<=k; i++)
        {
            g<<(double)v[st[i]].x<<" ";
            g<<(double)v[st[i]].y<<'\n';
        }
    f.close();
    g.close();
return 0;
}