Pagini recente » Cod sursa (job #2466214) | Cod sursa (job #2318391) | Cod sursa (job #1599494) | Cod sursa (job #2627401) | Cod sursa (job #2269043)
#include <bits/stdc++.h>
using namespace std;
#if 1
#define pv(x) cout<<#x<<" = "<<(x)<<"; ";cout.flush()
#define pn cout<<endl
#else
#define pv(x)
#define pn
#endif
// #if 1
#ifdef INFOARENA
ifstream in("infasuratoare.in");
ofstream out("infasuratoare.out");
#else
#define in cin
#define out cout
#endif
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pld = pair<ld, ld>;
using pdd = pair<double, double>;
#define pb push_back
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862;
const long double EPS = 1e-8;
const int inf_int = 1e9 + 5;
const ll inf_ll = 1e18 + 5;
const int NMax = 2e2 + 5;
const int mod = 1e9 + 7;
const int dx[] = {-1,0,0,+1}, dy[] = {0,-1,+1,0};
template<typename T>
T getOrientation(pair<T,T> a, pair<T,T> b, pair<T,T> c) {
T ans = a.first * b.second + b.first * c.second + c.first * a.second;
ans -= c.first * b.second + b.first * a.second + a.first * c.second;
return ans;
}
template<typename T>
void andrewScan(vector<pair<T,T>> v, vector<pair<T,T>>& ans) {
assert(v.size() > 2);
ans.clear();
sort(v.begin(), v.end());
ans.pb(v[0]);
ans.pb(v[1]);
for (int i = 2; i < (int)v.size(); ++i) {
T orient;
int last = ans.size() - 1;
while ( ans.size() >= 2 && (abs(orient = getOrientation(ans[last-1], ans[last], v[i])) < EPS || orient < 0) ) {
ans.pop_back();
last = ans.size() - 1;
}
ans.push_back(v[i]);
}
vector<pair<T,T>> up;
up.pb(v[v.size() - 1]);
up.pb(v[v.size() - 2]);
for (int i = v.size() - 3; i >= 0; --i) {
T orient;
int last = up.size() - 1;
while ( up.size() >= 2 && (abs(orient = getOrientation(up[last-1], up[last], v[i])) < EPS || orient < 0) ) {
up.pop_back();
last = up.size() - 1;
}
up.push_back(v[i]);
}
for (int i = 1; i < (int)up.size() - 1; ++i) {
ans.pb(up[i]);
}
}
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
int N;
in >> N;
vector<pdd> v(N);
for (auto& p : v) {
in >> p.first >> p.second;
}
vector<pdd> ans;
andrewScan(v, ans);
out << ans.size() << '\n';
out << fixed << setprecision(13);
for (auto& p : ans) {
out << p.first << ' ' << p.second << '\n';
}
return 0;
}