Pagini recente » Cod sursa (job #2270696) | Cod sursa (job #1951767) | Cod sursa (job #2477577) | Autentificare | Cod sursa (job #2208819)
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream in("infasuratoare.in");
ofstream out("infasuratoare.out");
int n, i;
int vf, poz, ok;
struct punct
{
double x, y;
};
punct a[120005];
int stiva[120005];
bool pus[120005];
bool cmp (punct a, punct b)
{
if(a.x > b.x)
return false;
if(a.x == b.x && a.y > b.y)
return false;
return true;
}
double determinant (punct a, punct b, punct c)
{
return ((a.x*b.y+b.x*c.y+c.x*a.y)-(b.y*c.x+c.y*a.x+a.y*b.x));
}
int main()
{
in>>n;
for(i=1; i<=n; i++)
in>>a[i].x>>a[i].y;
sort(a+1, a+n+1, cmp);
stiva[1]=1;
stiva[2]=2;
pus[2]=true;
vf=2;
poz=3;
ok=1;
while(!pus[1])
{
while(pus[poz])
{
if(poz==n)
ok=-1;
poz+=ok;
}
while( vf>=2 && determinant (a[stiva[vf-1]], a[stiva[vf]], a[poz])<0 )
{
pus[stiva[vf]]=false;
vf--;
}
vf++;
stiva[vf]=poz;
pus[poz]=true;
}
out<<vf-1<<'\n';
out<<setprecision(6)<<fixed;
for(i=2; i<=vf; i++)
out<<a[stiva[i]].x<<" "<<a[stiva[i]].y<<'\n';
return 0;
}