Pagini recente » Cod sursa (job #1521318) | Cod sursa (job #2955914) | Cod sursa (job #181733) | Monitorul de evaluare | Cod sursa (job #2173480)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
int n, viz[120005], st[120005];
struct db{
double x, y;
}a[120005];
void Citire()
{
fin >> n;
for(int i = 1; i <= n; i++)
fin >> a[i].x >> a[i].y;
}
inline bool Cmp(const db A, const db B)
{
if(A.y == B.y)
return A.x < B.x;
return A.y < B.y;
}
inline double F(int i, int j, int p)
{
return a[p].x * (a[i].y - a[j].y) +
a[p].y * (a[j].x - a[i].x) +
a[i].x * a[j].y - a[i].y * a[j].x;
}
void Rezolvare()
{
sort(a + 1, a + n + 1, Cmp);
int top;
st[1] = 1;
viz[2] = 1;
st[2] = 2;
top = 2;
for(int i = 3; i <= n; i++)
{
while(top > 1 && F(st[top - 1], st[top], i) < 0)
{
viz[st[top]] = 0;
top--;
}
viz[i] = 1;
st[++top] = i;
}
for(int i = n - 1; i >= 1; i--)
if(!viz[i])
{
while(top > 1 && F(st[top - 1], st[top], i) < 0)
{
viz[st[top]] = 0;
top--;
}
viz[i] = 1;
st[++top] = i;
}
fout << top - 1 << "\n";
for(int i = 1; i < top; i++)
fout << fixed << setprecision(13) << a[st[i]].x << " "
<< a[st[i]].y << "\n";
}
int main()
{
Citire();
Rezolvare();
return 0;
}