Pagini recente » Cod sursa (job #998721) | Cod sursa (job #1324071) | Cod sursa (job #2534284) | Cod sursa (job #972409) | Cod sursa (job #3214863)
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream cin ("infasuratoare.in");
ofstream cout ("infasuratoare.out");
struct punct
{
long double x;
long double y;
};
punct p0;
int delulu;
punct q[120005];
punct v[120005];
long double dist(punct a,punct b)
{
long double rasp = (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
return rasp;
}
int orientare(punct a,punct b,punct c)
{
long double v = (b.y-a.y)*(c.x-a.x) - (c.y-a.y)*(b.x-a.x);
if(v==0)
return 0;
if(v>0)
return 1;
return 2;
}
bool fcmp(punct a,punct b)
{
int o = orientare(p0,a,b);
if(o==0)
{
if(dist(p0,a)>=dist(p0,b))
return false;
return true;
}
else
{
if(o==2)
return true;
return false;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long double xmin = 2e9;
long double ymin = 2e9;
int delulu = 1;
for(int i=1;i<=n;i++)
{
cin >> v[i].x >> v[i].y;
if(v[i].y < ymin)
{
ymin = v[i].y;
xmin = v[i].x;
delulu = i;
continue;
}
if(v[i].y == ymin && v[i].x<xmin)
{
xmin = v[i].x;
delulu = i;
}
}
swap(v[1],v[delulu]);
p0 = v[1];
sort(v+2,v+n+1,fcmp);
int vf = 2;
q[1] = v[1];
q[2] = v[2];
for(int i=3;i<=n;i++)
{
while(vf>1 && orientare(q[vf-1],q[vf],v[i])!=2)
vf--;
q[++vf] = v[i];
}
cout << vf << '\n';
for(int i=1;i<=vf;i++)
cout << fixed <<setprecision(15) << q[i].x << ' ' << q[i].y << '\n';
return 0;
}