Pagini recente » Cod sursa (job #2179961) | Cod sursa (job #657110) | Cod sursa (job #2328160) | Cod sursa (job #2831205) | Cod sursa (job #2559350)
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
typedef pair<double, double> point;
const int nmax = 120005;
int n;
point v[nmax];
point st[nmax];
int top;
inline void read()
{
fin >> n;
for (int i = 1; i <= n; i++)
fin >> v[i].x >> v[i].y;
}
inline double cross(point &a, point &b, point &c)
{
//unghiul polar de la ab la c
return ((b.y - a.y)*(c.x - b.x) - (c.y - b.y)*(b.x - a.x));
}
bool cmp(point a, point b)
{
return (cross(v[1], a, b) < 0);
}
inline void sortt()
{
int pos = 1;
for (int i = 2; i <= n; i++)
if (v[i] < v[pos])
pos = i;
swap(v[1], v[pos]);
sort(v + 2, v + n + 1, cmp);
}
inline void convex_hull()
{
st[++top] = v[1];
st[++top] = v[2];
for (int i = 3; i <= n; i++)
{
while (top >= 2 && cross(st[top-1], st[top], v[i]) > 0)
top--;
st[++top] = v[i];
}
fout << fixed;
fout << top << "\n";
for (int i = 1; i <= top; i++)
fout << setprecision(12) << st[i].x << " " << st[i].y << "\n";
}
int main()
{
read();
sortt();
convex_hull();
return 0;
}