Pagini recente » Cod sursa (job #1838743) | Cod sursa (job #38045) | Cod sursa (job #728977) | Cod sursa (job #2473825) | Cod sursa (job #2060419)
#include <fstream>
#include <algorithm>
using namespace std;
#define eps 1e-12
#define nmax 120002
int n,i,h;
typedef struct punct
{
double x,y;
};
punct p[nmax];
punct v[nmax];
int s[nmax],ok[nmax];
inline int cmp1(double a,double b)
{
if(a+eps<b)
return 1;
if(b+eps<a)
return -1;
return 0;
}
bool cmp(const punct a,const punct b)
{
int t;
t=cmp1(a.x,b.x);
if(t!=0)
return t==0;
return (cmp1(a.y,b.y)==1);
}
int semn(punct a,punct b,punct c)
{
double A,B,C;
A=a.y-b.y;
B=b.x-a.x;
C=a.x*b.y-b.x*a.y;
return cmp1(A*c.x+B*c.y+C,0);
}
void rezolva()
{
int k,q;
sort(v+1,v+n+1,cmp);
s[1]=1;
s[2]=2;
ok[2]=1;
k=2;
i=3;
q=1;
while(!ok[1])
{
while(ok[i])
{
if(i==n)
q=-1;
i+=q;
}
while(k>=2&&semn(v[s[k-1]],v[s[k]],v[i])==-1)
{
ok[s[k--]]=0;
}
s[++k]=i;
ok[i]=1;
}
h=k-1;
}
int main()
{
ifstream in("infasuratoare.in");
ofstream out("infasuratoare.out");
in>>n;
for(i=1;i<=n;i++)
{
in>>v[i].x>>v[i].y;
}
rezolva();
out<<h<<endl;
out<<v[s[1]].x<<" "<<v[s[1]].y<<endl;
for(i=h;i>=2;i--)
{
out<<v[s[i]].x<<" "<<v[s[i]].y<<endl;
}
return 0;
}