Pagini recente » Cod sursa (job #2677991) | Cod sursa (job #2241118) | Cod sursa (job #1091090) | Cod sursa (job #1257654) | Cod sursa (job #1648392)
#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 unghi( point a,point b,point c)
{
return (b.y-a.y)*(c.x-a.x)-(c.y-a.y)*(b.x-a.x);
}
inline int comp( point a,point b)
{
return unghi(v[1],a,b)>0;
}
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].x==v[poz].x && 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 && unghi(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;
}