Pagini recente » Cod sursa (job #1544274) | Cod sursa (job #2797071) | Cod sursa (job #2254974) | Cod sursa (job #2085665) | Cod sursa (job #1650684)
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#define nmax 120003
using namespace std;
struct point
{
double x,y;
} v[nmax],s[nmax];
int nrp,head;
inline double crossprod( point a,point b,point c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
inline double comp(point a,point b)
{
return crossprod(v[1],a,b)<0;
}
inline void sort_p()
{
int poz=1;
for(int i=2;i<=nrp;i++)
if( v[i].x<v[poz].x) poz=i;
else if(v[i].y<v[poz].y) poz=i;
swap(v[1],v[poz]);
sort(v+2,v+nrp+1,comp);
}
int main()
{
int i;
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
scanf("%d",&nrp);
for(i=1;i<=nrp;i++) scanf("%lf%lf",&v[i].x,&v[i].y);
sort_p();
s[1]=v[1]; s[2]=v[2]; head=2;
for(i=3;i<=nrp;i++)
{
while( head>=2 && crossprod(s[head-1],s[head],v[i])>0 ) head--;
s[++head]=v[i];
}
printf("%d\n",head);
for(i=head;i>0;i--) printf("%lf %lf\n",s[i].x,s[i].y);
fclose(stdin);
fclose(stdout);
return 0;
}