Pagini recente » Cod sursa (job #480752) | Cod sursa (job #1159199) | Cod sursa (job #1069379) | Cod sursa (job #1830116) | Cod sursa (job #553305)
Cod sursa(job #553305)
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define nmax 120001
long n, poz, st[nmax], vf, pp;
struct punct
{
double x, y;
}p[nmax];
bool cmp(punct a, punct b)
{
return (a.x-p[poz].x)*(b.y-p[poz].y) > (b.x-p[poz].x)*(a.y-p[poz].y);
}
void push(int x)
{ st[++vf] = x; }
void pop()
{ vf--; }
void citire()
{
freopen("infasuratoare.in","r",stdin); scanf("%d", &n);
for(long i=1; i<=n; i++)
scanf("%lf %lf", &p[i].x, &p[i].y);
}
void afisare()
{
freopen("infasuratoare.out","w",stdout);
printf("%d\n", vf);
for(long i=1; i<=vf; i++)
printf("%lf %lf\n", p[st[i]].x, p[st[i]].y);
}
void caut_pmin()
{
poz = 1;
for(long i=1; i<=n; i++)
if(p[i].x <= p[poz].x)
if(p[i].x < p[poz].x || p[i].y < p[poz].y)
poz = i;
}
int directie(long p1, long p2, long p3)
{
return (p[p2].x-p[p1].x)*(p[p3].y-p[p1].y) > (p[p3].x-p[p1].x)*(p[p2].y-p[p1].y);
}
void solve()
{
caut_pmin();
punct pc; pc = p[1]; p[1] = p[poz]; p[poz] = pc; poz=1;
sort(p+2, p+1+n, cmp);
push(1); push(2);
for(long i=3; i<=n; i++)
{
if( directie(st[vf-1], st[vf], i) )
push(i);
else
{
while( !directie(st[vf-1], st[vf], i) && vf>=1)
pop();
push(i);
}
}
}
int main()
{
citire();
solve();
afisare();
return 0;
}