Cod sursa(job #2611212)

Utilizator drknss_Hehe hehe drknss_ Data 6 mai 2020 16:11:36
Problema Infasuratoare convexa Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.5 kb
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define forn(i,a,b) for (int i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pd pair <double, double>
#define sz(x) (int)((x).size())
#define make_unique(v) v.erase(unique(all(v)),v.end())
//#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 125100 + 11;

int n,k,m;

pd a[N],deq[N];

bool check(pd a,pd b,pd c){
    return ((b.ff - a.ff)*(c.ss - a.ss) - (b.ss - a.ss)*(c.ff - a.ff) > 0);
}


bool cmp(pd b, pd c){
	return !check(a[1], b, c);
}

int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);

ifstream cin("infasuratoare.in");
ofstream cout("infasuratoare.out");

    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> a[i].ff >> a[i].ss;
    }

    sort(a + 1, a + n + 1);
    sort(a + 2, a + n + 1, cmp);

    int Back = 2;

    deq[1] = a[1];
    deq[2] = a[2];

    ll ans = 0;
    for(int i = 3; i <= n; i++){

        while(Back >= 2 && check(deq[Back-1],deq[Back],a[i]))Back--;
        deq[++Back] = a[i];

    }

    cout << Back << '\n';
    cout << setprecision(6) << fixed;

    for(int i = Back; i >= 1; i--){
        cout << deq[i].ff << ' ' << deq[i].ss << '\n';
    }

 //   rc(t[1]);
return 0;
}