Pagini recente » Cod sursa (job #2924802) | Cod sursa (job #2894204) | Cod sursa (job #3209257) | Cod sursa (job #2937497) | Cod sursa (job #847450)
Cod sursa(job #847450)
#include <cstdio>
#include <algorithm>
#include <fstream>
#include <iomanip>
using namespace std;
#define x first
#define y second
#define NMAX 120005
typedef pair<double, double> Point;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
int n,k,i;
Point v[NMAX],st[NMAX];
void read()
{f>>n;
for(i=1;i<=n;++i)f>>v[i].x>>v[i].y;
}
inline double cross_product(const Point& A, const Point& B, const Point& C) {
return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
inline int cmp(const Point& p1, const Point& p2) {
return cross_product(v[1], p1, p2) < 0;
}
void sortare()
{int pos = 1;
for (int i = 2; i <= n; ++i)
if (v[i] < v[pos])
pos = i;
swap(v[1], v[pos]);
sort(v + 2, v + n + 1, cmp);
}
void convex_hull()
{sortare();
st[1] = v[1]; st[2] = v[2];
k = 2;
for (int i = 3; i <= n; ++i) {
while (k >= 2 && cross_product(st[k - 1], st[k], v[i]) > 0)
--k;
st[++k] = v[i];
}
}
void write() {
g << fixed;
g << k << "\n";
for (int i = k; i >= 1; --i)
g << setprecision(9) << st[i].x << " " << st[i].y << "\n";
}
int main()
{read();
convex_hull();
write();
return 0;
}