Pagini recente » Cod sursa (job #186802) | Cod sursa (job #1701801) | Cod sursa (job #946106) | Cod sursa (job #1458857) | Cod sursa (job #2365821)
#include <bits/stdc++.h>
#define NMax 120007
using namespace std;
ifstream fin ("infasuratoare.in");
ofstream fout ("infasuratoare.out");
struct DB
{
double x, y;
}a[NMax];
int n, st[NMax], viz[NMax], top;
void Read ()
{
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 int F (int p, int q, int k)
{
return a[q].x * (a[k].y - a[p].y) +
a[p].x * (a[q].y - a[k].y) +
a[k].x * (a[p].y - a[q].y);
}
void Infasuratoare ()
{
sort (a + 1, a + n + 1, CMP);
st[1] = 1;
st[2] = 2;
viz[2] = 1;
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] == 0)
{
while (F(st[top - 1], st[top], i) < 0)
{
viz[st[top]] = 0;
top--;
}
viz[i] = 1;
st[++top] = i;
}
}
}
void Output ()
{
fout << top - 1 << "\n";
for (int i = 1; i < top; i++)
fout << fixed << setprecision(12) << a[st[i]].x << " " << a[st[i]].y << "\n";
}
int main()
{
Read();
Infasuratoare();
Output();
return 0;
}