Pagini recente » Cod sursa (job #2900927) | Cod sursa (job #2502633) | Cod sursa (job #2534635) | Cod sursa (job #3196759) | Cod sursa (job #2926204)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
#define x first
#define y second
using Point = pair<double, double>;
const int NMAX = 12e4;
int N;
Point points[NMAX + 1];
vector<Point> st;
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);
}
void sortPoints() {
int pos = 1;
for(int i = 2; i <= N; i++) {
if(points[i] < points[pos]) {
pos = i;
}
}
swap(points[1], points[pos]);
sort(points + 2, points + N + 1, [] (const Point &A, const Point &B) {
return det(points[1], A, B) < 0;
});
// for(int i = 1; i <= N; i++) {
// cout << points[i].first << " " << points[i].second << '\n';
// }
}
void grahamScan() {
sortPoints();
st.push_back(points[1]);
st.push_back(points[2]);
for(int i = 3; i <= N; i++) {
while(st.size() >= 2 && det(st[st.size() - 2], st[st.size() - 1], points[i]) > 0) {
st.pop_back();
}
st.push_back(points[i]);
}
}
int main() {
fin >> N;
for(int i = 1; i <= N; i++) {
double x, y;
fin >> x >> y;
points[i] = Point(x, y);
}
grahamScan();
fout << st.size() << '\n';
for(const auto &it: st) {
fout << fixed << setprecision(9) << it.first << " " << it.second << '\n';
}
return 0;
}