Cod sursa(job #2407540)

Utilizator pragmaticAndrei Rotari pragmatic Data 16 aprilie 2019 22:49:46
Problema Infasuratoare convexa Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 3.21 kb
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define ld long double
# define point pair<ld,ld>
# define line pair<point,point>

int n;
ld x,y;
vector<point>vec,lowerpts,upperpts;

int operator ^(line a,line b)
{
	int x1 = a.second.first - a.first.first;
	int y1 = a.second.second - a.first.second;
	int x2 = b.second.first - b.first.first;
	int y2 = b.second.second - b.first.second;
	return x1*y2 - y1*x2;
}

int32_t main(){_
	freopen("infasuratoare.in","r",stdin);
	freopen("infasuratoare.out","w",stdout);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> x >> y;
		vec.pb(mp(x,y));
	}
	sort(vec.begin(),vec.end());
	point a = vec[0];
	point b = vec.back();
	for(auto it : vec)
	{
		ld ar = mp(a,it) ^ mp(a,b);
		if(ar <= 0) upperpts.pb(it);
		if(ar > 0) lowerpts.pb(it); 
	}
	vector<point>ansup;
	for(auto it : upperpts)
	{
		while(sz(ansup) > 1)
		{
			auto a = ansup[sz(ansup) - 2];
			auto itt = ansup[sz(ansup) - 1];
			auto b = it;
			ld ar = mp(a,itt) ^ mp(a,b);
			if(ar <= 0) break;
			ansup.pop_back();
		}
		ansup.push_back(it);
	}
	vector<point>ansdown;
	for(auto it : lowerpts)
	{
		while(sz(ansdown) > 1)
		{
			auto a = ansdown[sz(ansdown) - 2];
			auto itt = ansdown[sz(ansdown) - 1];
			auto b = it;
			ld ar = mp(a,itt) ^ mp(a,b);
			if(ar >= 0) break;
			ansdown.pop_back();
		}
		ansdown.push_back(it);
	}
	reverse(ansup.begin(),ansup.end());
	cout << sz(ansdown) + sz(ansup) - 2 << '\n';
	for(auto it : ansdown) cout << fixed << setprecision(7) << it.first << ' ' << it.second << '\n';
	for(int i = 1;i < sz(ansup) - 1;i++) cout << fixed << setprecision(7) << ansup[i].first << ' ' << ansup[i].second << '\n';
	return 0;
}