Pagini recente » Cod sursa (job #2879873) | Cod sursa (job #2132305) | Cod sursa (job #1872846) | Cod sursa (job #1964065) | Cod sursa (job #1645436)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstdio>
#define x first
#define y second
using namespace std;
ifstream fin("infasuratoare.in");
//ofstream fout("infasuratoare.out");
FILE *fout=fopen("infasuratoare.out","w");
typedef pair<double, double> Point;
Point v[120002],st[120002];
int n,i,top;
double cross_product(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 cross_product(v[1], p1, p2) < 0;}
void sortare()
{
int poz=1,i;
for(i=2;i<=n;i++)
if(v[i]<v[poz]) poz=i;
swap(v[1],v[poz]);
std::sort(v+2,v+n+1,cmp);
}
void infasuratoare()
{
int i;
st[1]=v[1]; st[2]=v[2]; top=2;
for(i=3;i<=n;i++)
{
while(top>=2&&cross_product(st[top-1],st[top],v[i])>0)
top--;
st[++top]=v[i];
}
}
int main()
{
fin>>n;
for(i=1;i<=n;i++)
fin>>v[i].x>>v[i].y;
sortare();
infasuratoare();
fprintf(fout,"%d\n",top);
while(top)
{
fprintf(fout,"%.9f %.9f\n",st[top].x,st[top].y);
top--;
}
return 0;
}