Pagini recente » Cod sursa (job #2096440) | Cod sursa (job #2039195) | Cod sursa (job #1976586) | Cod sursa (job #630219) | Cod sursa (job #1379401)
#include <bits/stdc++.h>
using namespace std;
#define Point pair<double,double>
#define x first
#define y second
const int Nmax = 120000 + 1;
Point P[Nmax];
Point stiva[Nmax];
int N, top;
double CCW(Point A, Point B, Point C)
{
return (B.x - A.x) * (C.y - A.y) -
(B.y - A.y) * (C.x - A.x);
}
bool cmp(const Point A, const Point B)
{
return CCW(P[1], A, B) < 0;
}
void sortPoints()
{
int ind = 1;
for ( int i = 2; i <= N; ++i )
if ( P[i] < P[ind] )
ind = i;
swap(P[1], P[ind]);
sort(P + 2, P + N + 1, cmp);
}
void convexHull()
{
stiva[ ++top ] = P[1];
stiva[ ++top ] = P[2];
for ( int i = 3; i <= N; ++i )
{
while ( top >= 2 && CCW(stiva[top - 1], stiva[top], P[i]) > 0 )
top--;
stiva[ ++top ] = P[i];
}
}
int main()
{
ifstream in("infasuratoare.in");
ofstream out("infasuratoare.out");
ios_base::sync_with_stdio(false);
in >> N;
for ( int i = 1; i <= N; ++i )
in >> P[i].x >> P[i].y;
sortPoints();
convexHull();
out << top << "\n";
for ( int i = top; i >= 1; i-- )
out << fixed << setprecision(10) << stiva[i].x << " " << stiva[i].y << "\n";
return 0;
}