Cod sursa(job #1090637)

Utilizator AlexandruVVasiliu Alexandru AlexandruV Data 22 ianuarie 2014 21:37:24
Problema Infasuratoare convexa Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.3 kb
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>

using namespace std;

ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");


struct  punct{double x;
              double y;
             };

punct v[120001];
int n;
int vis[120001];
int st[120001],head=0;
double EPS=1e-12;


int cmp(punct i,punct j)
{if(i.x<j.x) return 1;
 if(i.x>j.x) return 0;
 if(i.y<j.y) return 1;
 if(i.y>j.y) return 0;
}

void citire()
{f>>n;
int i;
for(i=1;i<=n;i++)
    f>>v[i].x>>v[i].y;
}

double intoarce(punct O,punct A,punct B)
{int i,j;
 return (A.x-O.x)*(B.y-O.y)-(B.x-O.x)*(A.y-O.y);
}

void solve()
{sort(v+1,v+n+1,cmp);
int i;
st[1]=1;
st[2]=2;
head=2;
vis[2]=1;
for(i=1;i<=n;i++)
   {if(vis[i]==1) continue;
    while(head>=2 && intoarce(v[st[head-1]],v[st[head]],v[i])<EPS)
              {vis[st[head]]=0;head--;}
    head++;
    st[head]=i;
    vis[i]=1;
   }

for(i=n;i>0;i--)
   {if(vis[i]==1) continue;
    while(head>=2 && intoarce(v[st[head-1]],v[st[head]],v[i])<EPS)
              {vis[st[head]]=0;head--;}
    head++;
    st[head]=i;
    vis[i]=1;
   }

g<<head-1<<endl;;
g<<setprecision(6)<<fixed;

for(i=2;i<=head;i++)
    g<<v[st[i]].x<<" "<<v[st[i]].y<<endl;
}

int main()
{citire();
 solve();

return 0;
}