Pagini recente » Cod sursa (job #3004967) | Cod sursa (job #964024) | Cod sursa (job #488084) | Rating Padure Damian (REDCRAFT) | Cod sursa (job #2173460)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
int st[120005], top, n;
bool viz[120005];
struct db{
double x, y;
}a[120006];
inline int F(int x, int y, int k)
{
return a[x].x * a[y].y + a[y].x * a[k].y + a[k].x * a[x].y
- a[k].x * a[y].y - a[k].y * a[x].x - a[y].x * a[x].y;
}
void Infasor()
{
st[1] = 1;
st[2] = 2;
viz[2] = 1;
top = 2;
for(int i = 3; i <= n; i++)
{
while(top && F(st[top - 1], st[top], i) < 0)
viz[st[top--]] = 0;
viz[i] = 1;
st[++top] = i;
}
for(int i = n - 1; i >= 1; i--)
if(!viz[i])
{
while(top && F(st[top - 1], st[top], i) < 0)
viz[st[top--]] = 0;
viz[i] = 1;
st[++top] = i;
}
fout << top - 1 << "\n";
for(int i = 1; i < top; i++)
fout << fixed << setprecision(13) << a[st[i]].x << " " << a[st[i]].y << "\n";
}
inline bool Cmp(const db A, const db B)
{
if(A.y == B.y)
return A.x < B.x;
return A.y < B.y;
}
void Citire()
{
fin >> n;
for(int i = 1; i <= n; i++)
fin >> a[i].x >> a[i].y;
sort(a + 1, a + n + 1, Cmp);
Infasor();
}
int main()
{
Citire();
return 0;
}