Cod sursa(job #2444218)

Utilizator bojemoiRadu Mamaliga bojemoi Data 30 iulie 2019 16:54:35
Problema Infasuratoare convexa Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.13 kb
#include<fstream>
#include<vector>
#include<algorithm>
#include<iomanip>

#define x first
#define y second
using namespace std;

ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");


struct Point {
	double x, y;
};


int n;
Point H[120004], S[120004];


double crossProduct(Point& A, Point& B, Point& C) {
	return (B.x - A.x) * (C.y - A.y) - (B.y - A.y) * (C.x - A.x);
}

inline int trigonometric(Point& p1, Point& p2) {

	return crossProduct(H[0], p1, p2) < 0;

}

int main() {
	fin >> n;

	for (int i = 0; i < n; ++i) {
		fin >> H[i].x >> H[i].y;
	}
	int pos = 0;
	for (int i = 1; i < n; ++i) {
		if (H[i].y < H[pos].y) {
			pos = i;
		}
		else if (H[i].y == H[pos].y) {
			if (H[i].x < H[pos].x) pos = i;
		}
	}
	swap(H[0], H[pos]);

	sort(H + 1, H + n, trigonometric);

	int k = 0;
	S[++k] = H[0];
	S[++k] = H[1];
	for (int i = 2; i < n; ++i) {
		while (k >= 2 && crossProduct(S[k - 1], S[k], H[i]) > 0)
			--k;
		S[++k] = H[i];
	}
	
	fout << k<<'\n';
	for (int i =k; i> 0; --i) {
		fout<<setprecision(12)<< S[i].x << ' ' << S[i].y << '\n';
	}
	




	return 0;
}