Cod sursa(job #1501637)

Utilizator sorynsooSorin Soo sorynsoo Data 13 octombrie 2015 18:18:12
Problema Infasuratoare convexa Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MAXN 120005
ifstream cin("infasuratoare.in");
ofstream cout("infasuratoare.out");
int n,mnp=1,st[MAXN],nrst;
struct pc
{
    double x,y;
}v[MAXN];
double determinant(pc A, pc B, pc C)
{
    return (B.x-A.x)*(C.y-A.y) - (C.x-A.x)*(B.y-A.y);
}
bool cmp(pc A, pc B)
{
    return determinant(v[1],A,B)>0;
}
int main()
{
    int i,j;

    cin>>n;
    for(i=1; i<=n; i++)
        cin>>v[i].x>>v[i].y;

    for(i=2; i<=n; i++)
    {
        if(v[i].x<v[mnp].x || (v[i].x==v[mnp].x && v[i].y<v[mnp].y))
            mnp=i;
    }

    swap(v[mnp],v[1]);
    sort(v+2,v+n+1,cmp);

    for(i=1; i<=n; i++)
    {
        while(nrst>=2 && determinant(v[st[nrst-1]],v[st[nrst]], v[i]) <0)
            nrst--;

        st[++nrst]=i;
    }
    cout<<nrst<<"\n";
    for(i=1; i<=nrst; i++)
        cout<<setprecision(12)<<v[st[i]].x<<" "<<v[st[i]].y<<"\n";





}