Pagini recente » Cod sursa (job #3293663) | Cod sursa (job #2445105) | Cod sursa (job #766801) | Cod sursa (job #2890465) | Cod sursa (job #2370614)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("infasuratoare.in");
ofstream fout ("infasuratoare.out");
const int Nmax = 120005;
int n, st[Nmax], top;
struct P
{
long double x, y;
};
P a[Nmax];
bool viz[Nmax];
inline bool CMP(const P A, const P B)
{
if(A.y == B.y)
return A.x < B.x;
return A.y < B.y;
}
inline bool D(long double x, long double y, long double x1, long double y1, long double x2, long double y2)
{
long double p;
p = x * y1 + x2 * y + x1 * y2 - x2 * y1 - x * y2 - x1 * y;
return (p < 0);
}
int main()
{
fin >> n;
for(int i = 1 ; i <= n ; i++)
fin >> a[i].x >> a[i].y;
sort(a + 1, a + n + 1, CMP);
top = 2;
st[1] = 1;
st[2] = 2;
viz[2] = true;
for(int i = 3 ; i <= n ; i++)
{
while(top && D(a[i].x, a[i].y, a[st[top - 1]].x, a[st[top - 1]].y, a[st[top]].x, a[st[top]].y ))
{
viz[st[top]] = false;
--top;
}
++top;
st[top] = i;
viz[i] = true;
}
for(int i = n ; i >= 1 ; i--)
if(!viz[i])
{
while(top && D(a[i].x, a[i].y, a[st[top - 1]].x, a[st[top - 1]].y, a[st[top]].x, a[st[top]].y ))
{
viz[st[top]] = false;
--top;
}
++top;
st[top] = i;
viz[i] = true;
}
fout << (top - 1) << "\n";
for(int i = 1 ; i < top ; i++)
fout << fixed << setprecision(12) << a[st[i]].x << " " << a[st[i]].y << "\n";
fin.close();
fout.close();
return 0;
}