Pagini recente » Cod sursa (job #2251445) | Cod sursa (job #406323) | Cod sursa (job #2198292) | Cod sursa (job #1987373) | Cod sursa (job #2874623)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
using namespace std;
struct punct
{
double x,y;
};
punct v[120005],stiva[120005];
int n,poz,nr;
double test_orientare(const punct &P0,const punct &P1,const punct &P2)
{
return (P0.x-P1.x)*(P1.y-P2.y)-(P1.x-P2.x)*(P0.y-P1.y);
}
bool cmp(const punct &P1,const punct &P2)
{
return test_orientare(v[1],P1,P2)>0;
}
int main()
{
int i;
f>>n;
for(i=1;i<=n;i++)
{
f>>v[i].x>>v[i].y;
}
poz=1;
for(i=2;i<=n;i++)
{
if(v[i].y<v[poz].y)
{
poz=i;
}
else
{
if(v[i].y==v[poz].y)
{
if(v[i].x<v[poz].x)
{
poz=i;
}
}
}
}
swap(v[1],v[poz]);
sort(v+2,v+n+1,cmp);
stiva[1]=v[1];
stiva[2]=v[2];
nr=2;
for(i=3;i<=n;i++)
{
while(nr>=2 && test_orientare(stiva[nr-1],stiva[nr],v[i])<0)
{
nr--;
}
nr++;
stiva[nr]=v[i];
}
g<<nr<<"\n";
for(i=2;i<=nr;i++)
{
g<<fixed<<setprecision(9)<<stiva[i].x<<" "<<stiva[i].y<<"\n";
}
g<<v[1].x<<" "<<v[1].y;
return 0;
}