Pagini recente » Cod sursa (job #1009807) | Cod sursa (job #2649482) | Cod sursa (job #2202731) | Cod sursa (job #3208279) | Cod sursa (job #2188085)
#include <fstream>
#include<algorithm>
#include<iomanip>
using namespace std;
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
int n,k;
struct punct{double x; double y;}p[120003];
punct s[120003];
double determinant(punct p1, punct p2, punct p3)
{
return(p1.x*p2.y + p2.x*p3.y + p1.y*p3.x - p2.y*p3.x - p3.y*p1.x - p1.y*p2.x);
}
bool cond(punct p1, punct p2)
{
return (determinant(p[1],p1,p2)>0);
}
int main()
{
int i,j;
f>>n;
j=1;
for(i=1;i<=n;i++)
{
f>>p[i].x>>p[i].y;
if(p[i].x<p[j].x || (p[i].x==p[j].x && p[i].y<p[j].y)) j=i;
}
swap(p[1],p[j]);
sort(p+2,p+n+1,cond);
s[1]=p[1]; s[2]=p[2];
k=2;
for(i=3;i<=n;i++)
{
while(determinant(s[k-1],s[k],p[i])<0) k--;
s[++k]=p[i];
}
g<<k<<'\n';
g<<fixed;
for(i=1;i<=k;i++) g<<setprecision(6)<<s[i].x<<' '<<setprecision(6)<<s[i].y<<'\n';
f.close();
g.close();
return 0;
}