Cod sursa(job #1627792)

Utilizator ris99Istrate Ruxandra ris99 Data 3 martie 2016 18:47:43
Problema Infasuratoare convexa Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <algorithm>
#include<iomanip>
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
struct punct
{ double x,y;
} v[120005];
int n,poz,st[120005],vf;
double panta(punct a,punct b,punct c)
{ return(c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
}
bool compar(punct a,punct b)
{ return panta(v[1],a,b)>0;
}

int main()
{ f>>n;
  poz=1;
  for(int i=1;i<=n;i++)
  { f>>v[i].x>>v[i].y;
    if(v[i].x<v[poz].x||v[i].x==v[poz].x &&v[i].y<v[poz].x)
      { poz=i;

      }
  }
  swap(v[1],v[poz]);
  sort(v+2,v+n+1,compar);
  st[++vf]=1;
  st[++vf]=2;
  for(int i=3;i<=n;i++)
  { while(vf>2&&panta(v[st[vf-1]],v[st[vf]],v[i])<0) vf--;
    st[++vf]=i;
  }
  g<<vf<<endl;
  for(int i=vf;i>=1;i--)
  g<<fixed<<setprecision(6)<<v[st[i]].x<<' '<<v[st[i]].y<<endl;

    return 0;
}