Pagini recente » Cod sursa (job #2536445) | Cod sursa (job #2089867) | Cod sursa (job #87882) | Cod sursa (job #611448) | Cod sursa (job #2953502)
#include <fstream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
const int NMAX = 120004;
struct pct
{
double x, y;
} v[NMAX];
int stiva[NMAX];
double ccw(pct a, pct b, pct c)
{
return (b.y - a.y) * (b.x - c.x) - (b.y - c.y) * (b.x - a.x);
}
bool cmp(pct a, pct b)
{
return ccw(v[1], a, b) < 0;
}
int main()
{
ifstream cin("infasuratoare.in");
ofstream cout("infasuratoare.out");
int n, i;
cin >> n;
int poz = 1;
for (i = 1; i <= n; i++)
{
cin >> v[i].x >> v[i].y;
if (v[i].x < v[poz].x)
{
poz = i;
}
}
swap(v[1], v[poz]);
sort(v + 2, v + n + 1, cmp);
stiva[1] = 1;
stiva[2] = 2;
int top = 2;
for (i = 3; i <= n; i++)
{
while (top > 1 and ccw(v[stiva[top - 1]], v[stiva[top]], v[i]) > 0)
{
top--;
}
stiva[++top] = i;
}
cout << top << "\n";
for (i = top; i >= 1; i--)
cout << fixed << setprecision(12) << v[stiva[i]].x << " " << v[stiva[i]].y << "\n";
}