Pagini recente » Cod sursa (job #1612673) | Cod sursa (job #2978672) | Cod sursa (job #2723713) | Cod sursa (job #1840988) | Cod sursa (job #1849008)
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<double, double> Point;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
const int MAX_N = 120005;
int n;
Point v[MAX_N];
Point st[MAX_N];
int head;
double det(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);
}
bool cmp(const Point& p1, const Point& p2) {
return det(v[1], p1, p2) < 0;
}
int main() {
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> v[i].x >> v[i].y;
}
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);
st[1] = v[1];
st[2] = v[2];
head = 2;
for (int i = 3; i <= n; i++) {
while (head >= 2 && det(st[head - 1], st[head], v[i]) > 0) {
--head;
}
st[++head] = v[i];
}
fout << fixed;
fout << head << "\n";
for (int i = head; i >= 1; i--) {
fout << setprecision(9) << st[i].x << " " << st[i].y << "\n";
}
return 0;
}