Pagini recente » Cod sursa (job #927797) | Cod sursa (job #1673474) | Cod sursa (job #1537653) | Cod sursa (job #2861354) | Cod sursa (job #2979722)
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
typedef pair<double, double > punct;
punct v[120005];
double det(punct a, punct b, punct c) {
return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
//
//double dist(punct a, punct b)
//{
// int dx = a.x - b.x, dy = a.y - b.y;
// return sqrt(dx * dx + dy * dy);
//}
//
//
//bool cmp2(punct a, punct b) {
// return det({0,0}, a, b) < 0;
//}
//
//double X, Y;
//bool comp(punct a, punct b)
//{
// return atan2(a.y - Y, a.x - X) > atan2(b.y - Y, b.x - X);
//}
int cadran(int x, int y) {
if (x > 0 && y >= 0)
return 1;
if (x >= 0 && y < 0)
return 4;
if (y > 0 && x <= 0)
return 2;
return 3;
}
int det(int X1, int Y1, int X2, int Y2, int X3, int Y3) {
return (X2 - X1) * (Y3 - Y1) - (X3 - X1) * (Y2 - Y1);
}
int cmp(const pair<int, int>& a, const pair<int, int>& b) {
int c1 = cadran(a.first, a.second);
int c2 = cadran(b.first, b.second);
if (c1 != c2)
return c1 < c2;
else {
int d = det(v[0].first, v[0].second, a.first, a.second, b.first, b.second);
if (d != 0)
return d < 0;
else
return a.first * a.first + a.second * a.second < b.first* b.first + b.second * b.second;
}
}
int main()
{
int n;
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> v[i].x >> v[i].y;
}
//sortare tip 1
int pos = 1;
for (int i = 2; i <= n; i++) {
if (v[i] < v[pos]) {
pos = i;
}
}
v[0] = v[pos];
swap(v[1], v[pos]);
sort(v + 1, v + 1 + n, cmp);
//sortare tip 2
//sort(v1 + 1, v1 + 1 + n, cmp);
//for (int i = 1; i <=n; i++) {
// cout << v[i].x << ' ' << v[i].y << '\n';
//}
vector<punct> S(120005);
S[1] = v[1];
S[2] = v[2];
int head = 2;
for (int i = 3; i <= n; i++) {
while (head >= 2 && det(S[head - 1], S[head], v[i]) > 0) {
head--;
}
S[++head] = v[i];
}
fout << head << '\n';
for (int i = head; i >= 1; i--) {
cout << fixed << setprecision(6) << S[i].x << ' ' << S[i].y << '\n';
}
return 0;
}