Pagini recente » Cod sursa (job #1959703) | Cod sursa (job #1358065) | Cod sursa (job #2090388) | Cod sursa (job #605160) | Cod sursa (job #1164532)
#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; }
pair<double, double> P[MAXN], st[MAXN];
int N, top, ind = 1;
inline double crossProduct(pair<double, double> a, pair<double, double> b, pair<double, double> c) {
return (b.first - a.first) * (c.second - a.second) - (c.first - a.first) * (b.second - a.second);
}
struct classComp {
inline bool operator () (const pair<double, double> &a, const pair<double, double> &b) const {
return crossProduct(P[1], a, b) < 0;
}
};
int main() {
fin >> N;
for(int i = 1 ; i <= N ; ++ i) {
fin >> P[i].first >> P[i].second;
if(P[ind] > P[i])
ind = i;
}
swap(P[ind], P[1]);
sort(P + 2, P + N + 1, classComp());
st[++ top] = P[1];
for(int i = 2 ; i <= N ; ++ i) {
while(top > 1 && crossProduct(st[top - 1], st[top], P[i]) > 0)
-- top;
st[++ top] = P[i];
}
fout << top << '\n' << fixed << setprecision(6);
for( ; top ; -- top)
fout << st[top].first << ' ' << st[top].second << '\n';
fin.close();
fout.close();
return 0;
}