Pagini recente » Cod sursa (job #1052153) | Statistici Dobrescu Diana (Diana523) | Istoria paginii runda/pre101/clasament | Cod sursa (job #2011521) | Cod sursa (job #1164755)
#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; }
int N, st[MAXN], ind = 1, top;
pair<double, double> P[MAXN];
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] = 1;
for(int i = 2 ; i <= N ; ++ i) {
while(top > 1 && crossProduct(P[st[top - 1]], P[st[top]], P[i]) > 0)
-- top;
st[++ top] = i;
}
fout << top << '\n' << fixed << setprecision(6);
for( ; top ; -- top)
fout << P[st[top]].first << ' ' << P[st[top]].second << '\n';
fin.close();
fout.close();
return 0;
}