Pagini recente » Cod sursa (job #630501) | Cod sursa (job #2717330) | Cod sursa (job #527471) | Cod sursa (job #2411884) | Cod sursa (job #2421605)
#include <bits/stdc++.h>
#define EPS 1e-12
#define NMAX 121105
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
int poz = 2;
struct punct
{
long double x, y;
} v[NMAX], st[NMAX];
long double det(punct a, punct b, punct c){
return ((a.x * b.y + a.y * c.x + b.x * c.y) - (b.y * c.x + a.y * b.x + a.x * c.y));
}
inline bool cmp1(punct a, punct b){
return a.y < b.y;
}
inline bool cmp2(punct a, punct b){
return (det(v[1], a, b) > 0.0);
}
inline bool test(punct a){
while(poz > 1 && det(st[poz - 1], st[poz], a) <= 0.0)
--poz;
st[++poz] = a;
}
int main()
{
int n;
fin >> n;
for(int i = 1; i <= n; ++i)
fin >> v[i].x >> v[i].y;
sort(v + 1, v + n + 1, cmp1);
sort(v + 2, v + n + 1, cmp2);
st[1] = v[1];
st[2] = v[2];
for(int i = 3; i <= n; ++i)
test(v[i]);
test(v[1]);
--poz;
fout << poz << '\n';
for(int i = 1; i <= poz; ++i)
fout << fixed << setprecision(6) << st[i].x << ' ' << st[i].y << '\n';
return 0;
}