Pagini recente » Cod sursa (job #81874) | Cod sursa (job #1865366) | Cod sursa (job #3200220) | Cod sursa (job #492797) | Cod sursa (job #2044396)
#include <bits/stdc++.h>
#define nmax 120003
using namespace std;
struct Punct
{
double x, y;
};
int st[nmax], top, v[nmax];
Punct a[nmax];
int n;
///retunrneaza mai mic ca 0 daca punctul a[p] este in semiplanul - al dreptei a[i],a[j]
double F(int i, int j, int p)
{
return a[p].x*(a[i].y - a[j].y) +
a[p].y*(a[j].x - a[i].x)+
a[i].x*a[j].y - a[j].x*a[i].y;
}
void Citire()
{
int i;
ifstream fin("infasuratoare.in");
fin >> n;
for( i =1; i <= n; i++)
fin >> a[i].x >> a[i].y;
fin.close();
}
inline bool Compara(Punct A, Punct B)
{
if(A.y == B.y) return A.x < B.x;
return A.y < B.y;
}
void Hill()
{
int i;
sort(a+1, a+1+n, Compara);
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 Afisare()
{
int i;
ofstream fout("infasuratoare.out");
fout << (top-1) << "\n";\
for(i = 1; i < top; i++)
fout << setprecision(12) << fixed << a[st[i]].x << " " << a[st[i]].y << "\n";
}
int main()
{
Citire();
Hill();
Afisare();
return 0;
}