Cod sursa(job #714554)
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#define NMAX 120010
#define EPS 0.00000000001
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
struct punct
{
double x, y;
int o;
}a[NMAX];
int n, st1[NMAX], st2[NMAX];
void Citeste()
{
int i;
f>>n;
for (i=1; i<=n; ++i) f>>a[i].x>>a[i].y;
}
inline bool cmp(punct A, punct B)
{
if (fabs(A.x-B.x)<EPS)
if (A.y-B.y<EPS) return 1;
else return 0;
else if (A.x-B.x<EPS) return 1;
else return 0;
}
double plan(punct A, punct B, punct C)
{
return A.x*B.y+B.x*C.y+C.x*A.y-B.y*C.x-C.y*A.x-A.y*B.x;
}
void Solve()
{
int i, m1=2, m2=2;
double P;
st1[1]=1; st1[2]=2; m1=2;
for (i=3; i<=n; ++i)
{
P=plan(a[st1[m1-1]], a[st1[m1]], a[i]);
if (P<EPS) st1[++m1]=i;
else
{
while (P>EPS && m1>2)
{
--m1;
P=plan(a[st1[m1-1]], a[st1[m1]], a[i]);
}
if (P<EPS) st1[++m1]=i;
}
}
for (i=2; i<=m1; ++i) a[st1[i]].o=1;
st2[1]=n; st2[2]=n-1; m2=2;
for (i=n-2; i>0; --i)
if (!a[i].o)
{
P=plan(a[st2[m2-1]], a[st2[m2]], a[i]);
if (P<EPS) st2[++m2]=i;
else
{
while (P>EPS && m2>2)
{
--m2;
P=plan(a[st2[m2-1]], a[st2[m2]], a[i]);
}
if (P<EPS) st2[++m2]=i;
}
}
g<<m1+m2-2<<"\n";
for (i=m1; i>0; --i) g<<fixed<<a[st1[i]].x<<" "<<a[st1[i]].y<<"\n";
for (i=m2-1; i>1; --i) g<<fixed<<a[st2[i]].x<<" "<<a[st2[i]].y<<"\n";
}
int main()
{
Citeste();
sort(a+1, a+n+1, cmp);
Solve();
f.close();
g.close();
return 0;
}