Pagini recente » Cod sursa (job #2326010) | Cod sursa (job #1996186) | Cod sursa (job #2786998) | Cod sursa (job #1392043) | Cod sursa (job #1990816)
#include <fstream>
#include <iomanip>
#include <algorithm>
#define x first
#define y second
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
int n,mipoz;
typedef pair <double, double> Punct;
Punct p[120010];
int st[10000000];
int vf;
double determinant(Punct A, Punct B, Punct C)
{
return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
int comp(Punct A, Punct B)
{if(determinant(p[1], A, B) < 0)
return true;
return false;
}
void read()
{ fin >> n;
for(int i = 1; i <= n; i++)
{
fin >> p[i].x >> p[i].y;
if(p[i] < p[mipoz]) mipoz = i;
}
}
int main()
{
swap(p[1], p[mipoz]);
sort(p+ 2, p + n + 1, comp);
st[++vf] = 1;
for(int i = 2; i <= n; i++)
{
while(vf > 1 && determinant(p[st[vf-1]], p[st[vf]], p[i]) > 0)
vf--;
st[++vf] = i;
}
fout << vf << '\n';
while(vf)
{
fout <<setprecision(6) << fixed << p[st[vf]].x << ' ' << p[st[vf]].y << '\n';
vf--;
}
return 0;
}