Pagini recente » Cod sursa (job #1668375) | Cod sursa (job #2890314) | Istoria paginii winter-challenge-2008/clasament/runda-1 | Cod sursa (job #2025212) | Cod sursa (job #2280373)
#include <ios>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <algorithm>
#define NMAX 120010
using std::sort;
using std::fixed;
using std::setprecision;
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];
inline void swap(Point& a, Point& b) {
Point aux = a;
a = b;
b = aux;
}
double crossProduct(Point a, Point b, Point c) {
return (a.x - b.x) * (c.y - b.y) - (c.x - b.x) * (a.y - b.y);
}
bool operator<(Point a, Point b) {
return crossProduct(b, p[0], a) < 0;
}
int main() {
fin >> n;
for (int i = 0; i < n; i++)
fin >> p[i].x >> p[i].y;
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[0], p[min]);
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 && crossProduct(st[vf - 1], st[vf], p[i]) >= 0)
vf--;
st[++vf] = p[i];
}
fout << fixed;
fout << setprecision(6);
fout << vf << '\n';
for (int i = 1; i <= vf; i++)
fout << st[i].x << ' ' << st[i].y << '\n';
fout.close();
return 0;
}