Pagini recente » Cod sursa (job #505552) | Cod sursa (job #729045) | Cod sursa (job #1213746) | Cod sursa (job #3239077) | Cod sursa (job #3239129)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct Punct {
double x, y;
} v[120002], st[120002];
int n, i, top;
static inline double Det(Punct p1, Punct p2, Punct p3) {
return ((p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y));
}
static inline bool Cmp(Punct a, Punct b) {
return (Det(v[1], a, b) > 0);
}
int main() {
fin >> n;
for(i = 1; i <= n; i++) fin >> v[i].x >> v[i].y;
int poz = 1;
for(int i = 2; i <= n; i++) {
if(v[i].y < v[poz].y || (v[i].y == v[poz].y && v[i].x < v[poz].x)) poz = i;
}
swap(v[1], v[poz]);
sort(v + 2, v + n + 1, Cmp);
st[++top] = v[1];
for(i = 2; i <= n + 1; i++) {
while(top >= 2 && Det(st[top - 1], st[top], v[i]) < 0) top--;
st[++top] = v[i];
}
fout << top - 1 << "\n";
fout << fixed << setprecision(6);
for(i = 1; i < top; i++) fout << st[i].x << " " << st[i].y << "\n";
return 0;
}