Pagini recente » Cod sursa (job #2314702) | Cod sursa (job #2202582) | Cod sursa (job #1414295) | Cod sursa (job #2680971) | Cod sursa (job #1372615)
# include <fstream>
# include <algorithm>
# include <iomanip>
# define nmax 120001
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
struct elem
{
double x,y;
}a[nmax];
bool cmp (elem A, elem B)
{
double dx1, dx2, dy1, dy2;
dx1=A.x-a[1].x;
dx2=B.x-a[1].x;
dy1=A.y-a[1].y;
dy2=B.y-a[1].y;
if (dy1*dx2 >= dx1*dy2) return 0;
else return 1;
}
int i,j,n,m,x,y,VV,poz;
int st[nmax];
double det (elem a, elem b, elem c)
{
return (a.x*b.y + b.x*c.y + c.x*a.y - a.x*c.y - c.x*b.y - b.x*a.y);
}
void infasuratoare ()
{
st[1]=1; st[2]=2; VV=2;
for (int i=3; i<=n; ++i)
{
while (VV>1 && det (a[st[VV-1]], a[st[VV]], a[i])<0)
--VV;
st[++VV]=i;
}
g<<VV<<"\n";
for (int i=1; i<=VV; ++i)
g<<fixed<<setprecision(6)<<a[st[i]].x<<" "<<a[st[i]].y<<"\n";
}
int main ()
{
f>>n; poz=1;
for (i=1; i<=n; ++i)
{
f>>a[i].x>>a[i].y;
if (a[i].x<a[poz].x) poz=i;
else if (a[i].x==a[poz].x && a[i].y<=a[poz].y) poz=i;
}
swap (a[1], a[poz]);
sort (a+2, a+n+1, cmp);
infasuratoare ();
return 0;
}