Pagini recente » Cod sursa (job #399154) | Cod sursa (job #2265357) | Cod sursa (job #687705) | Cod sursa (job #205413) | Cod sursa (job #1123194)
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
const char infile[] = "infasuratoare.in";
const char outfile[] = "infasuratoare.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 120005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
#define x first
#define y second
int N, top;
pair<double, double> P[MAXN], st[MAXN];
int ind = 1;
inline double crossPoint(pair<double, double> A, pair<double, double> B, pair<double, double> C) {
return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}
struct classComp {
inline bool operator () (const pair<double, double> &a, const pair<double, double> &b) const {
return crossPoint(P[1], a, b) < 0;
}
};
int main() {
fin >> N;
for(int i = 1 ; i <= N ; ++ i) {
fin >> P[i].x >> P[i].y;
if(P[ind].x > P[i].x || (P[ind].x == P[i].x && P[ind].y > P[i].y))
ind = i;
}
swap(P[ind], P[1]);
sort(P + 2, P + N + 1, classComp());
st[++ top] = P[1];
st[++ top] = P[2];
for(int i = 3 ; i <= N ; ++ i) {
while(top > 1 && crossPoint(st[top - 1], st[top] , P[i]) > 0)
-- top;
st[++ top] = P[i];
}
fout << top << fixed << setprecision(6) << '\n';
for(; top ; -- top) {
fout << st[top].first << ' ' << st[top].second << '\n';
}
fin.close();
fout.close();
return 0;
}