Cod sursa(job #2442894)

Utilizator mihai.alphamihai craciun mihai.alpha Data 25 iulie 2019 18:45:37
Problema A+B Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 3.17 kb
#include <bits/stdc++.h>

using namespace std;

int n, t;

const int maxn = 15e4 + 5;

struct at  {
    long long x, y;
    int ind;
};

at v[maxn];

int sti[maxn];
bool viz[maxn];
int i1, i0;
int d1, d0;

vector <at> conv[maxn];
int nrconv;

bool cmp(at a, at b) {
	if (a.x == b.x) {
		return a.y < b.y;
	}
	return a.x < b.x;
}

struct comparator  {
    bool operator ()  (const at &a, const at &b) const {
        if (a.x == b.x) {
            return a.y < b.y;
        }
        return a.x < b.x;
    }
};

inline long long ver(at i, at st, at dr) {
	return (st.x - i.x) * (dr.y - i.y) - (st.y - i.y) * (dr.x - i.x);
}

vector <at> vv;
set <at, comparator> ramas;

struct comp1  {
    bool operator ()  (const at &a, const at &b) const  {
        return a.ind < b.ind;
    }
};

priority_queue <at, vector <at>, comp1 > pq;

vector <pair <at, at> > leg[maxn];

int main()  {
    freopen("a.in", "r", stdin);
    cin >> n >> t;
    vv.reserve(n + 1);
    int cn = n;
    for(int i = 1;i <= n;i++)  {
        cin >> vv[i].x >> vv[i].y;
        vv[i].ind = i;
        v[i].x = vv[i].x, v[i].y = vv[i].y, v[i].ind = i;
        ramas.insert(vv[i]);
    }
//    for(int i = 1;i <= n;i++)  {
//        cerr << v[i].x << " " << v[i].y << "\n";
//    }
    while(n)  {
//        for(int i = 1;i <= n;i++)
//            cerr << v[i].x << " " << v[i].y << "  ";
//        cerr << "\n";
        sort(v + 1, v + n + 1, cmp);
        int stid = 2;
        memset(viz, 0, sizeof viz);
        memset(sti, 0, sizeof sti);
        sti[1] = 1;
        sti[2] = 2;

        for (int i = 1; i <= n; i++) {
            if (viz[i])
                continue;
            while (stid >= 2 && ver(v[sti[stid - 1]], v[sti[stid]], v[i]) <= 0)
                viz[sti[stid--]] = 0;
            sti[++stid] = i;
            viz[i] = 1;
        }
        for (int i = n - 1; i > 0; i--) {
            if (viz[i])
                continue;
            while (stid >= 2 && ver(v[sti[stid - 1]], v[sti[stid]], v[i]) <= 0)
                viz[sti[stid--]] = 0;
            sti[++stid] = i;
            viz[i] = 1;
        }
        for(int i = 1;i <= stid - 1;i ++)  {
            conv[nrconv].push_back(v[sti[i]]);
            ramas.erase(v[sti[i]]);
            n--;
        }
        vector <at> noq;
        for(int i = 1;i <= n;i++)  {
            v[i] = *ramas.begin();
            noq.push_back(v[i]);
            ramas.erase(ramas.begin());
        }
        for(auto x : noq)
            ramas.insert(x);
        nrconv++;

    }
//    for(int i = 0;i < nrconv;i++)  {
//        for(auto x : conv[i])
//            cerr << x.x << " " << x.y << "  ";
//        cerr << "\n";
//    }
    for(int i = 0;i < nrconv - 1;i++)  {
        for(auto x : conv[i])
            for(auto y : conv[i + 1])  {
                int difx;
                int dify;
                difx = x.x - y.x;
                dify = x.y - y.y;
                if(abs(difx) + abs(dify) == 1)  {
                    leg[i].push_back({x, y});
                }
            }
    }
//    int cnt = cn;
//    int curr = -1, sh = 0;
//    while(cnt)  {
//        if(curr < sh)  {
//            curr++;
//            for(auto x : conv[sh])
//                pq.push(x);
//        }
//    }
    return 0;
}