Pagini recente » Cod sursa (job #622253) | Cod sursa (job #653825) | Cod sursa (job #622218) | Cod sursa (job #2565406) | Cod sursa (job #2555484)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
#define x first
#define y second
#define NMAX 120005
typedef pair<double,double> Punct;
Punct v[NMAX];
Punct s[NMAX];
int n;
int head;
void citeste()
{
fin>>n;
for(int i=1;i<=n;i++)
{
fin>>v[i].x>>v[i].y;
}
}
int cross_product(const Punct& a,const Punct& b,const Punct& c)
{
return (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);
}
int comp(const Punct& A,const Punct& B)
{
return (cross_product(v[1],A,B) < 0);
}
void sorteaza()
{
int pos = 1;
for(int i=2;i<=n;i++)
if(v[i] < v[pos])
pos = i;
swap(v[1],v[pos]);
sort(v+2,v+n+1,comp);
}
void infasuratoare()
{
sorteaza();
s[1] = v[1];
s[2] = v[2];
head = 2;
for(int i = 3;i <= n; ++i)
{
while(head >= 2 && cross_product(s[head-1], s[head], v[i]) > 0)
--head;
s[++head] = v[i];
}
}
void afisare()
{
fout<<fixed;
fout<<head<<'\n';
for(int i=head;i>=1;i--)
{
fout<<setprecision(9)<<v[i].x<<" "<<v[i].y<<'\n';
}
}
int main()
{
citeste();
infasuratoare();
afisare();
return 0;
}