Pagini recente » Cod sursa (job #2024942) | Cod sursa (job #2743729) | Cod sursa (job #180411) | Cod sursa (job #2318249) | Cod sursa (job #2280298)
#include <ios>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <algorithm>
#define NMAX 120010
using std::sort;
std::ifstream fin("infasuratoare.in");
std::ofstream fout("infasuratoare.out");
struct Point {
double x, y;
};
int n;
Point p[NMAX];
int min, vf;
Point st[NMAX];
bool operator<(Point a, Point b) {
double x = atan2(a.y - p[min].y, a.x - p[min].x);
double y = atan2(b.y - p[min].y, b.x - p[min].x);
double r1 = (a.x - p[min].x) * (a.x - p[min].x) + (a.y - p[min].y) * (a.y - p[min].y);
double r2 = (b.x - p[min].x) * (b.x - p[min].x) + (b.y - p[min].y) * (b.y - p[min].y);
return x < y || x == y && r1 < r2;
}
inline void swap(Point& a, Point& b) {
Point aux = a;
a = b;
b = aux;
}
double position(Point a, Point b, Point c) {
return (c.x - b.x) * (a.y - b.y) - (a.x - b.x) * (c.y - b.y);
}
int main() {
fin >> n;
for (int i = 0; i < n; i++)
fin >> p[i].x >> p[i].y;
min = 0;
for (int i = 1; i < n; i++)
if (p[i].x < p[min].x || p[i].x == p[min].x && p[i].y < p[min].y)
min = i;
swap(p[min], p[0]);
sort(p + 1, p + n);
vf = 2;
st[1] = p[0];
st[2] = p[1];
for (int i = 2; i < n; i++) {
while (vf > 2 && position(st[vf - 1], st[vf], p[i]) <= 0)
vf--;
if (position(st[vf - 1], st[vf], p[i]) > 0)
st[++vf] = p[i];
}
fout << vf << '\n';
for (int i = 1; i <= vf; i++)
fout << st[i].x << ' ' << st[i].y << '\n';
fout.close();
return 0;
}