Pagini recente » Cod sursa (job #2203444) | Cod sursa (job #123248) | Cod sursa (job #2737161) | Cod sursa (job #39275) | Cod sursa (job #1915310)
#include <bits/stdc++.h>
#define Nmax 120005
#define eps 0.000000000001
using namespace std;
struct Point
{
double x,y;
bool operator <(const Point &A) const
{
if(fabs(y-A.y)<=eps) return A.x-x>eps;
return A.y-y>eps;
}
} a[Nmax];
int st[Nmax],top,used[Nmax],n;
inline bool Good(Point &A, Point &B, Point &C)
{
double alfa = B.y-A.y;
double beta = A.x-B.x;
double gama = B.x*A.y - A.x*B.y;
return (alfa*C.x + beta*C.y + gama <= eps);
}
inline void Convex_hull()
{
int i,sign=1;
st[++top]=1; st[++top]=2;
used[2]=1;
for(i=3;i;i+=sign)
{
if(used[i]) continue;
if(i==n) sign=-1;
while(top>1 && !Good(a[st[top-1]],a[st[top]],a[i])) used[st[top--]]=0;
st[++top]=i; used[i]=1;
}
}
int main()
{
int i;
ifstream cin("infasuratoare.in");
ofstream cout("infasuratoare.out");
cin>>n;
for(i=1;i<=n;++i) cin>>a[i].x>>a[i].y;
sort(a+1,a+n+1);
Convex_hull();
cout<<top-1<<"\n";
cout<<setprecision(10)<<fixed;
for(i=1;i<top;++i) cout<<a[st[i]].x<<" "<<a[st[i]].y<<"\n";
return 0;
}