Pagini recente » Cod sursa (job #1555362) | Cod sursa (job #860722) | Cod sursa (job #801014) | Cod sursa (job #1798352) | Cod sursa (job #3214617)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct vrajeala
{
double x, y;
bool operator < (const vrajeala A) const
{
if (y == A.y)
return x < A.x;
return y < A.y;
}
}a[120005];
int n, st[120005], top;
bitset <120005> viz;
int F(vrajeala A, vrajeala B, vrajeala C)
{
return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
int main()
{
int i;
fin >> n;
for (i = 1; i <= n; i++)
fin >> a[i].x >> a[i].y;
sort(a + 1,a + n + 1);
st[++top] = 1;
st[++top] = 2;
viz[2] = 1;
for (i = 3; i <= n; i++)
{
while (top >= 2 and F(a[st[top - 1]], a[st[top]], a[i]) <= 0)
{
viz[st[top]] = 0;
top--;
}
st[++top] = i;
viz[i] = 1;
}
for (i = n; i >= 1; i--)
if (viz[i] == 0)
{
while (top >= 2 and F(a[st[top - 1]], a[st[top]], a[i]) <= 0)
top--;
st[++top] = i;
}
fout << top - 1 << "\n";
for (i = 1; i < top; i++)
fout << setprecision(12) << fixed << a[st[i]].x << " " << a[st[i]].y << "\n";
return 0;
}