Pagini recente » Cod sursa (job #1609085) | Cod sursa (job #1114440) | Cod sursa (job #1307979) | Cod sursa (job #179992) | Cod sursa (job #3219786)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct Punct
{
double x, y;
bool operator< (Punct A) const
{
if (y == A.y) return x < A.x;
return y < A.y;
}
};
Punct a[125000];
int v[125000], st[125000], top, n;
double Plan(Punct A, Punct B, Punct C)
{
double a, b, c;
a = A.y - B.y;
b = B.x - A.x;
c = A.x * B.y - A.y * B.x;
return a * C.x + b * C.y + c;
}
void Afis(int top)
{
if (top == 0) return;
Afis(top - 1);
fout << setprecision(6) << a[st[top]].x << " " << a[st[top]].y << "\n";
}
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[1] = v[1] = v[2] = 1;
st[top = 2] = 2;
for (i = 3; i <= n; i++)
{
while (top > 1 &&
Plan(a[st[top - 1]], a[st[top]], a[i]) <= 0)
{
v[st[top]] = 0;
top--;
}
st[++top] = i;
v[i] = 1;
}
v[1] = 0;
for (i = n - 1; i >= 1; i--)
{
if (v[i]) continue;
while (top > 1 &&
Plan(a[st[top - 1]], a[st[top]], a[i]) <= 0)
top--;
st[++top] = i;
}
fout << top - 1 << "\n";
fout << fixed;
Afis(top - 1);
return 0;
}