Pagini recente » Cod sursa (job #1068294) | Cod sursa (job #2668634) | Cod sursa (job #669084) | Cod sursa (job #2328330) | Cod sursa (job #1479702)
#include <cstdio>
#include <algorithm>
#define x first
#define y second
using namespace std;
typedef pair<double,double> point;
int n,head;
point p[120010];
point stiva[120010];
double unghi(const point& A,const point& B,const point& C)
{
return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
int cmp(const point &p1,const point &p2)
{
return unghi(p[1],p1,p2)<0;
}
int main()
{
freopen("infasuratoare.in","r",stdin);
freopen("infasuratoare.out","w",stdout);
scanf ("%d",&n);
int i;
for(i=1;i<=n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
int poz=1;
for(i=2;i<=n;i++) if(p[i]<p[poz]) poz=i;
swap(p[1],p[poz]);
sort(p + 2,p + n + 1, cmp);
stiva[1]=p[1]; stiva[2]=p[2]; head=2;
for(i=3;i<=n;i++)
{
while(head>=2 && unghi(stiva[head-1],stiva[head],p[i])>0) --head;
stiva[++head]=p[i];
}
printf("%d\n",head);
for(i=1;i<=head;i++) printf("%lf %lf\n",stiva[i].x,stiva[i].y);
fclose(stdin);
fclose(stdout);
return 0;
}