Cod sursa(job #2266629)

Utilizator BogdanisarBurcea Bogdan Madalin Bogdanisar Data 22 octombrie 2018 20:08:33
Problema Infasuratoare convexa Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 2.17 kb
#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>;
#define pb push_back
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862;
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};

ld orientation(pld a, pld b, pld c) {
    ld 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;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    in >> N;
    vector<pld> v(N);
    pld mn = {1e18,1e18};
    for (auto& p : v) {
        in >> p.first >> p.second;
        mn = min(mn, p);
    }

    vector<pld> ans;
    ans.pb(mn);
    // pv(mn.first);pv(mn.second);pn;
    pld currPoint = mn;
    int cnt = 0;
    while (true) {
        assert(cnt < 1e5);
        ++cnt;
        pld leftmost = (v[0] == currPoint) ? v[1] : v[0];
        for (auto p : v) {
            if (p == currPoint || p == leftmost) {
                continue;
            }

            if (orientation(currPoint, leftmost, p) > 0) {
                leftmost = p;
            }
        }

        // pv(currPoint.first);pv(currPoint.second);pn;
        // pv(leftmost.first);pv(leftmost.second);pn;pn;

        if (leftmost == ans[0]) {
            break;
        }
        ans.pb(leftmost);
        currPoint = leftmost;
    }

    out << ans.size() << '\n';
    out << fixed << setprecision(14);
    for (auto p : ans) {
        out << p.first << ' ' << p.second << '\n';
    }
    
    return 0;
}