Pagini recente » Cod sursa (job #1907224) | Cod sursa (job #1146591) | Cod sursa (job #2343869) | Cod sursa (job #1953478) | Cod sursa (job #1958025)
#include <bits/stdc++.h>
#define NMAX 120005
#define x first
#define y second
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
typedef pair<double,double> Point;
int n,head;
Point s[NMAX],v[NMAX];
inline double crossProduct(Point A, Point B, Point C) {
B.x-=A.x;
B.y-=A.y;
C.x-=A.x;
C.y-=A.y;
return B.x*C.y-B.y*C.x;
}
bool cmp(Point a, Point b) {
return crossProduct(v[1],a,b) < 0;
}
void sortPoints() {
int pos=1;
for(int i=2;i<=n;i++) if(v[i]<v[pos]) pos=i;
swap(v[1],v[pos]);
sort(v+2,v+n+1,cmp);
}
void convexHull() {
s[1]=v[1];
s[2]=v[2];
head=2;
for(int i=3;i<=n;i++) {
while(head>=2&&crossProduct(s[head-1],s[head],v[i])>0) {
head--;
}
s[++head]=v[i];
}
}
int main()
{
fin>>n;
for(int i=1;i<=n;i++) fin>>v[i].x>>v[i].y;
sortPoints();
convexHull();
fout<<fixed;
fout<<head<<'\n';
while(head) {
fout<<setprecision(9)<<s[head].x<<' '<<s[head].y<<'\n';
head--;
}
return 0;
}