Pagini recente » Cod sursa (job #2405853) | Cod sursa (job #563863) | Cod sursa (job #1176821) | Cod sursa (job #1000153) | Cod sursa (job #1737293)
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct Point {
double x, y;
};
Point v[120100], st[120100];
int n, head;
void Read();
void Write();
void Convex_hull();
double Aria(Point A, Point B, Point C);
int cmp(const Point &A, const Point &B);
int main()
{
Read();
Convex_hull();
Write();
}
void Convex_hull()
{
int poz = 1;
for (int i = 2; i <= n; i++)
if ( v[i].x < v[poz].x )
poz = i;
swap(v[1], v[poz]);
sort(v + 2, v + n + 1, cmp);
st[1] = v[1];
st[2] = v[2];
head = 2;
for (int i = 3; i <= n; i++)
{
while ( Aria(st[head - 1], st[head], v[i]) > 0 )
head--;
st[++head] = v[i];
}
}
int cmp(const Point &A, const Point &B)
{
return (Aria(v[1], A, B) < 0);
}
double Aria(Point A, Point B, Point C)
{
return (B.x - A.x) * (C.y - A.y) + (A.y - B.y) * (C.x - A.x);
}
void Write()
{
fout << head << '\n';
fout << fixed << setprecision(6);
for (int i = head; i; i--)
fout << st[i].x << ' ' << st[i].y << '\n';
fout.close();
}
void Read()
{
fin >> n;
for (int i = 1; i <= n; i++)
fin >> v[i].x >> v[i].y;
fin.close();
}