Pagini recente » Cod sursa (job #2657755) | Cod sursa (job #1950035) | Cod sursa (job #3252867) | Cod sursa (job #3206144) | Cod sursa (job #2526820)
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <fstream>
#define NMAX 120005
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
vector < pair < double , double > > points;
pair < double , double > st[NMAX];
int N, top;
double crossProduct(pair <double,double> A,pair <double,double> B,pair <double,double> C)
{
return (B.first - A.first) * (C.second - A.second) - (B.second - A.second) * (C.first - A.first);
}
int CMP(pair <double,double> A, pair <double,double> B)
{
return crossProduct(points[0],A,B) < 0;
}
void sortPoints()
{
int pos = 0;
for(int i = 1; i < points.size(); i++){
if(points[pos] > points[i]){
points[pos] = points[i];
}
}
swap(points[0],points[pos]);
sort(points.begin() + 1, points.end(),CMP);
}
void convexHull()
{
top = 2;
sortPoints();
st[1] = points[0];
st[2] = points[1];
for(int i = 2; i < points.size(); i++){
while(top >= 2 && crossProduct(st[top - 1],st[top],points[i]) > 0){
top--;
}
st[++top] = points[i];
}
}
int main()
{
double x, y;
fin >> N;
for(int i = 1; i <= N; i++){
fin >> x >> y;
points.push_back(make_pair(x,y));
}
convexHull();
fout << fixed;
fout << top << "\n";
for(int i = top; i >= 1; i--){
fout << setprecision(9) << st[i].first << " " << st[i].second << "\n";
}
return 0;
}