Cod sursa(job #1958189)

Utilizator RaduhhNuhay Bebru Raduhh Data 8 aprilie 2017 07:28:14
Problema Infasuratoare convexa Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <bits/stdc++.h>

using namespace std;

struct dot{
    double x;
    double y;
};
int n,i,st=0x3f3f3f3f,js=0x3f3f3f3f,poz,last;
dot t[120005],rez[120005];

double f(dot a, dot b, dot c)
{
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}

bool cmp(dot a, dot b)
{
    return f(t[1],a,b)<0;
}

int main() 
{   
    ifstream cin("infasuratoare.in");
    ofstream cout("infasuratoare.out");
    cin>>n;
    for (i=1; i<=n; i++)
    {
        cin>>t[i].x>>t[i].y;
        if (t[i].x<st) st=t[i].x,js=t[i].y,poz=i; else if (t[i].x==st) if (t[i].y<js) t[i].y=js,poz=i;
    }
    swap(t[1],t[poz]);
    sort(t+2,t+n+1,cmp);
    rez[1]=t[1];
    rez[2]=t[2];
    last=2;
    for (i=3; i<=n; i++)
    {
        while (last>=2 && f(rez[last-1],rez[last],t[i])>0) last--;
        last++;
        rez[last]=t[i];
    }
    cout<<last<<'\n';
    for (i=n; i>=1; i--) cout<<setprecision(12)<<fixed<<rez[i].x<<" "<<rez[i].y<<'\n';
}