Pagini recente » Cod sursa (job #3213878) | Cod sursa (job #1436560) | Borderou de evaluare (job #1000147) | Cod sursa (job #623437) | Cod sursa (job #2269163)
#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());
vector<int> idx;
idx.pb(0);
idx.pb(1);
bool goUp = true;
for (int i = 2; i > 0; (goUp) ? ++i : --i) {
T orient;
int last = idx.size() - 1;
while ( idx.size() >= 2 && (abs(orient = getOrientation(v[idx[last-1]], v[idx[last]], v[i])) < EPS || orient < 0) ) {
idx.pop_back();
--last;
}
idx.push_back(i);
if (i == (int)v.size() - 1) {
goUp = false;
idx.pb(v.size() - 2);
i -= 1;
}
// pv(v[i].first);pv(v[i].second);pn;
// for (auto k : idx) {
// out << v[k].first << ' ' << v[k].second << '\n'; ////
// }
// out << '\n';
}
for (int i : idx) {
ans.pb(v[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;
}