Pagini recente » Cod sursa (job #1675736) | Cod sursa (job #1740417) | Cod sursa (job #606660) | Cod sursa (job #1089997) | Cod sursa (job #1512983)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iomanip>
#define x first
#define y second
using namespace std;
typedef pair<double, double> point;
vector<point> pts;
int n;
int hull[120001];
double cross_product(const point &O, const point &A, const point &B) {
return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
}
int main()
{
#ifdef LOCAL
freopen("input", "r", stdin);
#else
ifstream cin("infasuratoare.in");
ofstream cout("infasuratoare.out");
#endif // LOCAL
cin >> n;
for (int i = 0; i < n; ++i) {
double x, y;
cin >> x >> y;
pts.push_back({x, y});
}
iter_swap(pts.begin(), min_element(pts.begin(), pts.end()));
sort(pts.begin() + 1, pts.end(), [&O = pts[0]](const point &A, const point &B) {
return cross_product(O, A, B) < 0;
});
hull[0] = 0;
hull[1] = 1;
int k = 2;
for (int i = 2; i < n; ++i) {
while (k >= 2 && cross_product(pts[hull[k - 2]], pts[hull[k - 1]], pts[i]) > 0) {
--k;
}
hull[k] = i;
++k;
}
cout << k << '\n' << setprecision(6) << fixed;
for (int i = k - 1; i >= 0; --i) {
cout << pts[hull[i]].x << ' ' << pts[hull[i]].y << '\n';
}
return 0;
}