Pagini recente » Borderou de evaluare (job #821617) | Borderou de evaluare (job #2079319) | Borderou de evaluare (job #2079706) | Cod sursa (job #2341977) | Cod sursa (job #2942501)
#include <fstream>
#include <iostream>
#include <algorithm>
#include<iomanip>
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
struct point
{
double x, y;
};
int n, m;
int st[100005];
point v[100005];
long long cross_product(const point& a, const point& b, const point& c)
{
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
bool cmp(const point& a, const point& b)
{
return cross_product(v[1], a, b) < 0;
}
int main()
{
f >> n;
for (int i = 1; i <= n; i++)
f >> v[i].x >> v[i].y;
for (int i = 2; i <= n; i++)
if ((v[i].x < v[1].x) || (v[1].x == v[i].x && v[i].y < v[1].y))
swap(v[i], v[1]);
sort(v + 2, v + n + 1, cmp);
m = 2;
st[1] = 1;
st[2] = 2;
for (int i = 3; i <= n; i++)
{
while (m > 2 && cross_product(v[st[m - 1]], v[st[m]], v[i]) >= 0)
m--;
m++;
st[m] = i;
}
while (cross_product(v[1], v[st[m]], v[st[m-1]]) == 0)
m--;
int start = m;
for (int i = 1; i <= m; i++)
if ((v[st[i]].y < v[st[start]].y) ||
(v[st[i]].y == v[st[start]].y && v[st[i]].x < v[st[start]].x))
start = i;
g << m << "\n";
for (int i = start; i >= 1; i--)
g << v[st[i]].x << " " << v[st[i]].y << "\n";
for (int i = m; i > start; i--)
g << fixed<<setprecision(6)<<v[st[i]].x << " " << v[st[i]].y << "\n";
return 0;
}