Pagini recente » Cod sursa (job #2065903) | Cod sursa (job #1060365) | Cod sursa (job #919139) | Cod sursa (job #817669) | Cod sursa (job #1090637)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
struct punct{double x;
double y;
};
punct v[120001];
int n;
int vis[120001];
int st[120001],head=0;
double EPS=1e-12;
int cmp(punct i,punct j)
{if(i.x<j.x) return 1;
if(i.x>j.x) return 0;
if(i.y<j.y) return 1;
if(i.y>j.y) return 0;
}
void citire()
{f>>n;
int i;
for(i=1;i<=n;i++)
f>>v[i].x>>v[i].y;
}
double intoarce(punct O,punct A,punct B)
{int i,j;
return (A.x-O.x)*(B.y-O.y)-(B.x-O.x)*(A.y-O.y);
}
void solve()
{sort(v+1,v+n+1,cmp);
int i;
st[1]=1;
st[2]=2;
head=2;
vis[2]=1;
for(i=1;i<=n;i++)
{if(vis[i]==1) continue;
while(head>=2 && intoarce(v[st[head-1]],v[st[head]],v[i])<EPS)
{vis[st[head]]=0;head--;}
head++;
st[head]=i;
vis[i]=1;
}
for(i=n;i>0;i--)
{if(vis[i]==1) continue;
while(head>=2 && intoarce(v[st[head-1]],v[st[head]],v[i])<EPS)
{vis[st[head]]=0;head--;}
head++;
st[head]=i;
vis[i]=1;
}
g<<head-1<<endl;;
g<<setprecision(6)<<fixed;
for(i=2;i<=head;i++)
g<<v[st[i]].x<<" "<<v[st[i]].y<<endl;
}
int main()
{citire();
solve();
return 0;
}