Pagini recente » Cod sursa (job #1743898) | Cod sursa (job #956334) | Cod sursa (job #1950039) | Cod sursa (job #1887163) | Cod sursa (job #553289)
Cod sursa(job #553289)
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define nmax 120001
long n, poz, st[nmax], vf, pp;
struct punct
{
double x, y;
double up;
}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()
{
printf("%d\n", vf);
long i=0;
while(++i<=vf)
{
printf("%f %f\n", p[st[i]].x, p[st[i]].y);
//pop();
}
}
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;
}
double dist(int i)
{
return cos( abs(p[poz].x-p[i].x) / sqrt( pow(p[poz].x-p[i].x,double(2))+pow(p[poz].y-p[i].y, double(2)) ) );
}
void unghi_p()
{
for(long i=1; i<=n; i++)
if(i==poz)
p[i].up = 0;
else
p[i].up = dist(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()
{
double o;
caut_pmin();
freopen("infasuratoare.out","w",stdout);
punct pc; pc = p[1]; p[1] = p[poz]; p[poz] = pc; poz=1;
sort(p+2, p+1+n, cmp);
//for(int i=1; i<=n; i++)
//printf("%lf %lf \n", p[i].x, p[i].y);
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;
}