Pagini recente » Cod sursa (job #951007) | Cod sursa (job #1106993) | Cod sursa (job #1396327) | Cod sursa (job #322529) | Cod sursa (job #1479705)
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iomanip>
#define x first
#define y second
using namespace std;
ifstream t1("infasuratoare.in");
ofstream t2("infasuratoare.out");
typedef pair<double,double> point;
int n,head;
point p[120010];
point stiva[120010];
double unghi(const point& A,const point& B,const point& C)
{
return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
int cmp(const point &p1,const point &p2)
{
return unghi(p[1],p1,p2)<0;
}
int main()
{
t1>>n;
int i;
for(i=1;i<=n;i++) t1>>p[i].x>>p[i].y;
int poz=1;
for(i=2;i<=n;i++) if(p[i]<p[poz]) poz=i;
swap(p[1],p[poz]);
sort(p + 2,p + n + 1, cmp);
stiva[1]=p[1]; stiva[2]=p[2]; head=2;
for(i=3;i<=n;i++)
{
while(head>=2 && unghi(stiva[head-1],stiva[head],p[i])>0) --head;
stiva[++head]=p[i];
}
t2 << fixed;
t2 << head << "\n";
for (int i = head; i >= 1; --i)
t2 << setprecision(6) << stiva[i].x << " " << stiva[i].y << "\n";
return 0;
}