Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #2941574) | Istoria paginii runda/infinity-2022-8 | Cod sursa (job #1915046)
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream fi("infasuratoare.in");
ofstream fo("infasuratoare.out");
struct punct{double x, y;} a[120001], st[120001];
int n, sf;
bool cmp (punct a, punct b)
{
return (a.x < b.x or (a.x == b.x and a.y < b.y));
}
bool semn(punct a,punct b, punct c)
{
return ((a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y)>=0);
}
int main ()
{
fi >> n;
for (int i = 1; i <= n; i++) fi >> a[i].x >> a[i].y;
sort (a+1, a+n+1, cmp);
st[++sf] = a[1];
st[++sf] = a[2];
for (int i = 3; i <= n; i++)
{
while (sf > 1 and !semn(st[sf-1], st[sf], a[i])) sf--;
st[++sf] = a[i];
}
for (int i = n-1; i >= 1; i--)
{
while ( ! semn(st[sf-1], st[sf], a[i])) sf--;
st[++sf] = a[i];
}
fo << fixed << setprecision(6);
fo << sf-1 << '\n';
for (int i = 1; i <= sf-1; i++)
fo << st[i].x << ' ' << st[i].y << '\n';
return 0;
}