Pagini recente » Cod sursa (job #169845) | Cod sursa (job #2103990) | Cod sursa (job #1223930) | Cod sursa (job #1717949) | Cod sursa (job #2151091)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
struct punct
{
double x,y;
};
punct v[120001],stiva[120001];
int n,poz,varf;
inline double ceas_trig(const punct &P0,const punct &P1,const punct &P2)
{
return (P1.x-P0.x)*(P2.y-P0.y)-(P2.x-P0.x)*(P1.y-P0.y);
}
inline int cmp(const punct &P1,const punct &P2)
{
return ceas_trig(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].x<v[poz].x)
{
poz=i;
}
else
{
if(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);
stiva[1]=v[1];
stiva[2]=v[2];
varf=2;
for(i=3;i<=n;i++)
{
while(varf>=2 && ceas_trig(stiva[varf-1],stiva[varf],v[i])>0)
{
varf--;
}
varf++;
stiva[varf]=v[i];
}
g<<varf<<"\n";
for(i=varf;i>=1;i--)
{
g<<fixed<<setprecision(9)<<stiva[i].x<<" "<<stiva[i].y<<"\n";
}
return 0;
}