Cod sursa(job #923774)
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#define eps 1.e-12
using namespace std;
struct st
{
double x,y;
};
st s[120005],aux;
int v[120005];
int ccw(st a,st b,st c)
{
double cp;
cp=(b.x-a.x)*(c.y-b.y)-(b.y-a.y)*(c.x-b.x);
if(fabs(cp)<eps)
return 0;
if(cp>=eps)
return 1;
return -1;
}
bool cmp(st x,st y)
{
return ccw(s[0],x,y)>eps;
}
int main()
{
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
int n,i,top;
scanf("%d",&n);
scanf("%lf%lf",&s[0].x,&s[0].y);
for(i=1;i<n;i++)
{
scanf("%lf%lf",&s[i].x,&s[i].y);
if((s[i].y-s[0].y)<-eps)
{
aux=s[0];
s[0]=s[i];
s[i]=aux;
}
else
if(fabs(s[i].y-s[i].x)<eps)
{
if(s[i].x-s[0].x<-eps)
{
aux=s[0];
s[0]=s[i];
s[i]=aux;
}
}
}
sort(s+1,s+n,cmp);
v[0]=0;
v[1]=1;
s[n]=s[0];
top=1;
i=2;
while(i<=n)
{
if(ccw(s[v[top-1]],s[v[top]],s[i])>0)
{v[++top]=i;i++;}
else
top--;
}
printf("%d\n",top);
for(i=0;i<top;i++)
printf("%.6lf %.6lf\n",s[v[i]].x,s[v[i]].y);
return 0;
}