Pagini recente » Cod sursa (job #2863442) | Cod sursa (job #83788) | Cod sursa (job #3237350) | Cod sursa (job #1149899) | Cod sursa (job #2633987)
#include<bits/stdc++.h>
using namespace std;
ifstream fin ("infasuratoare.in");
ofstream fout("infasuratoare.out");
int n,st[120002],vf;
bool viz[120002];
struct pct
{
double x,y;
} v[120002];
bool cmp (const pct &a,const pct &b)
{
if (a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
double panta (pct a,pct b,pct c)
{
return (b.y-a.y)*(c.x-a.x) - (c.y-a.y)*(b.x-a.x);
}
void rez ()
{
st[1]=1,st[2]=2;
int i=3,pas=1;
vf=2;
while (st[vf]!=1)
{
while (viz[i]==1)
{
if (i==n)
pas=-1;
i=i+pas;
}
while (panta(v[st[vf-1]],v[st[vf]],v[i])>0 && vf>=2)
{
viz[st[vf]]=0;
vf--;
}
st[++vf]=i;
viz[i]=1;
}
}
int main ()
{
fin>>n;
int i;
for (i=1;i<=n;i++)
fin>>v[i].x>>v[i].y;
sort(v+1,v+n+1,cmp);
rez();
fout<<vf-1<<'\n';
for (i=2;i<= vf+1;i++)
{
fout<<fixed<<setprecision(8)<<v[st[i]].x<<' ';
fout<<fixed<<setprecision(8)<<v[st[i]].y<<'\n';
}
return 0;
}