Pagini recente » Cod sursa (job #24257) | Cod sursa (job #2120231) | Cod sursa (job #2585052) | Cod sursa (job #156157) | Cod sursa (job #1915305)
#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)
{
int alfa = B.y-A.y;
int beta = A.x-B.x;
int gama = B.x*A.y - A.x*B.y;
return (1LL*alfa*C.x + 1LL*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;
}