Pagini recente » Istoria paginii runda/bulangandit2/clasament | Cod sursa (job #1813331) | Cod sursa (job #1127867) | Cod sursa (job #1711232) | Cod sursa (job #1237297)
#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; }
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);
}
pair<double, double> P[MAXN];
struct classComp {
inline bool operator () (const pair<double, double> &a, const pair<double, double> &b) const {
return crossProduct(P[1], a, b) < 0;
}
};
int st[MAXN], top, N;
int main() {
int minIndex = -1;
fin >> N;
for(int i = 1 ; i <= N ; ++ i) {
fin >> P[i].first >> P[i].second;
if(minIndex == -1 || P[minIndex] > P[i])
minIndex = i;
}
swap(P[1], P[minIndex]);
sort(P + 2, P + N + 1, classComp());
st[++top] = 1;
st[++top] = 2;
for(int i = 3 ; i <= N ; ++ i) {
while(top >= 2 && crossProduct(P[st[top-1]], P[st[top]], P[i]) > 0)
-- top;
st[++top] = i;
}
for(fout << top << '\n' << fixed << setprecision(6); top ; -- top)
fout << P[st[top]].first << ' ' << P[st[top]].second << '\n';
fin.close();
fout.close();
return 0;
}