Pagini recente » Cod sursa (job #20576) | Cod sursa (job #2838013) | Cod sursa (job #408256) | Cod sursa (job #575659) | Cod sursa (job #1226584)
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps=1.e-12;
struct point
{
double x,y;
};
point p[120050];
int st[120005];
int ccw(point a,point b,point 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(point a,point b)
{
if (ccw(p[0],a,b)==-1)
return 0;
return 1;
}
int main()
{
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
int n,i,top;
double tx,ty;
scanf("%d%lf%lf",&n,&tx,&ty);
p[0].x=tx;p[0].y=ty;
for (i=1;i<n;++i)
{
scanf("%lf%lf",&tx,&ty);
p[i].x=tx;
p[i].y=ty;
if ((fabs(ty-p[0].y)<eps&&tx-p[0].x<=-eps)||(ty-p[0].y<=-eps))
swap(p[0],p[i]);
}
sort (p+1,p+n,cmp);
p[n]=p[0];
st[0]=0;st[1]=1;top=1;i=2;
while (i<=n)
{
if (ccw(p[st[top-1]],p[st[top]],p[i])==1)
{
st[++top]=i;
++i;
}
else
--top;
}
printf("%d\n",top);
for (register int j=0;j<top;++j)
printf("%lf %lf\n",p[st[j]].x,p[st[j]].y);
return 0;
}