Pagini recente » Cod sursa (job #1179372) | Cod sursa (job #2964147) | Cod sursa (job #2960992) | Cod sursa (job #721881) | Cod sursa (job #2753927)
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const double eps=1e-10;
const int NMAX=10005;
struct POINT
{
double x,y;
};
POINT p[NMAX],LL;
int h[NMAX];
double cp(POINT P1,POINT P2,POINT P3)
{
return (P2.x-P1.x)*(P3.y-P2.y)-(P2.y-P1.y)*(P3.x-P2.x);
}
int CCW(POINT P1,POINT P2,POINT P3)
{
double C=cp(P1,P2,P3);
if(fabs(C)<eps)
return 0;
if(C>=eps)
return 1;
return -1;
}
bool cmp(POINT a,POINT b)
{
return CCW(LL, a, b) > 0;
}
int main()
{
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
int n,i,top;
scanf("%d%lf%lf",&n,&p[0].x,&p[0].y);
for(i=1;i<n;++i)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
if(p[i].y-p[0].y<=-eps || (fabs(p[i].y-p[0].y)<eps && p[i].x-p[0].x<=-eps))
{
swap(p[0],p[i]);
}
}
LL=p[0];
sort(p+1,p+n,cmp);
h[0]=0;h[1]=1;
p[n]=p[0];
top=1;
i=2;
while(i<=n)
{
if( CCW( p[h[top-1]], p[h[top]], p[i]) > 0)
{
h[++top]=i;
++i;
}else{
top--;
}
}
printf("%d\n",top);
for(i=0;i<top;++i)
{
printf("%.6lf %.6lf\n",p[h[i]].x,p[h[i]].y);
}
return 0;
}