Pagini recente » Cod sursa (job #2263799) | Cod sursa (job #628135) | Cod sursa (job #925657) | Cod sursa (job #1153228) | Cod sursa (job #2365827)
#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], v[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 Hill()
{
int i;
sort(a + 1, a + n + 1, CMP);
st[++top] = 1;
st[++top] = 2;
v[2] = 1;
for(i = 3; i <= n; i++)
{
while(top > 1 && F(st[top - 1], st[top], i) < 0)
{
v[st[top]] = 0;
top--;
}
st[++top] = i;
v[i] = 1;
}
for(i = n - 1; i >= 1; i--)
if(v[i] == 0)
{
while(F(st[top - 1], st[top], i) < 0)
{
v[st[top]] = 0;
top--;
}
st[++top] = i;
v[i] = 1;
}
}
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();
Hill();
Output();
return 0;
}