Pagini recente » Cod sursa (job #1190688) | Cod sursa (job #1087274) | Cod sursa (job #1001638) | Cod sursa (job #226183) | Cod sursa (job #3246747)
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
struct coord
{
double x,y;
};
coord v[120002];
double m(coord a,coord b,coord c)
{
return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
}
int cmp(coord x,coord y)
{
if(m(v[1],x,y)>0)
return 1;
return 0;
}
int main()
{
int n,poz=1,st[120002],vf,i;
fin>>n;
for (i=1; i<=n; i++)
{
fin>>v[i].x>>v[i].y;
if (v[i].x<v[poz].x || v[i].x==v[poz].x && v[i].y<v[poz].y)
{
poz=i;
}
}
swap(v[1],v[poz]);
sort(v+2,v+n+1,cmp);
st[1]=1;
st[2]=2;
vf=2;
for (i=3; i<=n; i++)
{
while (vf>=2 && m(v[st[vf-1]],v[st[vf]],v[i])<0)
vf--;
st[++vf]=i;
}
fout<<vf<<'\n';
for (int i=vf; i>=1; i--)
fout<<fixed<<setprecision(6)<<v[st[i]].x<<" "<<v[st[i]].y<<"\n";
return 0;
}