Pagini recente » Cod sursa (job #1332538) | Cod sursa (job #1011091) | Cod sursa (job #3262690) | Cod sursa (job #2139280) | Cod sursa (job #1437399)
#include <iostream>
#include <fstream>
#include <utility>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
typedef pair < double, double > Point;
const int NMax = 120005;
int n,head;
Point v[NMax],stak[NMax];
inline double cross_product(const Point &A, const Point &B, const Point &C){
return (B.first - A.first) * (C.second - A.second) - (B.second - A.second) * (C.first - A.first);
}
inline bool cmp(const Point &p1, const Point &p2){
return cross_product(v[1], p1, p2) < 0;
}
inline void swep(Point &a, Point &b){
Point aux = a;
a = b;
b = aux;
}
void sort_points(){
int pos = 1;
for(int i = 2; i <= n; i++){
if(v[i] < v[pos]){
pos = i;
}
}
swep(v[1],v[pos]);
sort(v + 2, v + n + 1, cmp);
}
void convex_hull(){
sort_points();
stak[1] = v[1];
stak[2] = v[2];
head = 2;
for(int i = 3; i <= n; i++){
while(head >= 2 && cross_product(stak[head - 1], stak[head], v[i]) > 0){
head--;
}
stak[++head] = v[i];
}
}
int main()
{
fin >> n;
for(int i = 1; i <= n; i++){
fin >> v[i].first >> v[i].second;
}
convex_hull();
fout << fixed;
fout << head << "\n";
for(int i = head; i > 0; i--){
fout << setprecision(9) << stak[i].first << " " << stak[i].second << "\n";
}
return 0;
}