Pagini recente » Cod sursa (job #1301700) | Cod sursa (job #677624) | Cod sursa (job #391630) | Cod sursa (job #1335068) | Cod sursa (job #1138314)
#include <fstream>
#include <algorithm>
#include <iomanip>
#define x first
#define y second
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
typedef pair<double,double>Punct;
Punct p[120001],st[120001];
int n, k;
inline double Rotation(const Punct& P1, const Punct& P2, const Punct& P3)
{
return (P2.x-P1.x)*(P3.y-P1.y)-(P3.x-P1.x)*(P2.y-P1.y);
}
bool cmp(const Punct& A, const Punct& B)
{
return Rotation(p[1],A,B)<0;
}
int main()
{
fin>>n;
int pos=1;
for(int i = 1; i<= n; i++ )
{
fin>>p[i].x>>p[i].y;
if(p[i]<p[pos])
pos=i;
}
swap(p[1], p[pos]);
sort(p+2,p+n+1,cmp);
st[++k]=p[1];
st[++k]=p[2];
for(int i = 3; i<= n; i++ )
{
while(k>=2 && Rotation(st[k-1],st[k],p[i])>0)
k--;
st[++k]=p[i];
}
fout<<k<<'\n';
for(int i = k; i>0; i-- )
fout<<setprecision(12)<<fixed<<st[i].x<< ' ' <<st[i].y<<'\n';
fin.close();
fout.close();
return 0;
}