Pagini recente » Cod sursa (job #1074635) | Cod sursa (job #1125349) | Cod sursa (job #1786527) | Cod sursa (job #1099931) | Cod sursa (job #1756360)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
#define x first
#define y second
typedef pair<double, double> Point;
const int MAX_N = 120005;
const double EPS = 1e-12;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
int n;
Point v[MAX_N];
bool vis[MAX_N];
int st[MAX_N], head;
void read() {
f >> n;
for (int i = 1; i <= n; ++i)
f >> v[i].x >> v[i].y;
}
double cross_product(Point O, Point A, Point B)
{
return (A.x - O.x) * (B.y - O.y) - (B.x - O.x) * (A.y - O.y);
}
void write()
{
g << head - 1 << "\n";
g <<setprecision(6)<<fixed;
for (int i = 1; i < head; ++i)
g << v[st[i]].x << " " << v[st[i]].y << "\n";
}
void convex_hull() {
sort(v + 1, v + n + 1);
st[1] = 1; st[2] = 2; head = 2;
vis[2] = 1;
int i=1,p=1;
while(i>0)
{
if (i==n) p=-p;
i+=p;
if (vis[i]) continue;
while (head >= 2 && cross_product(v[st[head - 1]], v[st[head]], v[i]) < EPS)
vis[st[head--]] = 0;
st[++head] = i;
vis[i] = 1;
}
}
int main()
{
read();
convex_hull();
write();
}