Pagini recente » Cod sursa (job #2829192) | Cod sursa (job #183880) | Cod sursa (job #677688) | Cod sursa (job #2104047) | Cod sursa (job #2753921)
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
const int nmax = 120000;
const double eps = 1.e-18;
struct POINT
{
double x, y;
};
POINT p[nmax+5];
POINT LL;
double cp(const POINT P1, const POINT P2, const POINT P3)
{
return (P2.x-P1.x)*(P3.y-P2.y)-(P2.y-P1.y)*(P3.x-P2.x);
}
int ccw(const POINT P1, const POINT P2, const POINT P3)
{
if(fabs(cp(P1,P2,P3))<eps)
return 0;
if(cp(P1,P2,P3)>=eps)
return 1;
return -1;
}
bool cmp(POINT P1, POINT P2)
{
return ccw(LL, P1, P2)>0;
}
int n, top, h[nmax+5], i;
int main()
{
fin>>n;
fin>>p[0].x>>p[0].y;
for(i=1; i<n; i++)
{
in>>p[i].x>>p[i].y;
if(p[i].y - p[0].y<=-eps || (fabs(p[i].y-p[0].y)<eps && p[i].x - p[0].x <= -eps))
{
swap(p[0],p[i]);
}
}
LL = p[0];
sort(p+1, p+n, cmp);
p[n] = p[0];
h[0]=0;
h[1]=1;
top=1;
i=2;
while(i<=n)
{
if(ccw(p[h[top-1]],p[h[top]],p[i])>0)
{
h[++top]=i;
i++;
}
else
{
top--;
}
}
fout<<top;
fout<<"\n";
for(i=0; i<top; i++)
{
fout<<fixed<<setprecision(6)<<p[h[i]].x<<" "<<fixed<<setprecision(6)<<p[h[i]].y<<"\n";
}
return 0;