Cod sursa(job #1390842)

Utilizator EpictetStamatin Cristian Epictet Data 17 martie 2015 13:16:44
Problema Pachete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <fstream>
#include <algorithm>
#include <vector>
#define x first
#define y second
using namespace std;
ifstream fin ("pachete.in");
ofstream fout ("pachete.out");
long long N, Ox, Oy, sol, D[50010];
vector < pair < long long, long long > > C[5];

long long Afla_Numarul_Minim_De_Drumuri(vector < pair < long long, long long > > V)
{
    D[0] = 0; // descrescator
    for (long long i = 0; i < V.size(); i++)
    {
        long long st = 1, dr = D[0], mij, w = 1;
        while (st <= dr)
        {
            mij = (st + dr) / 2;
            if (D[mij] <= V[i].y) {
                w = 0;
                dr = mij - 1;
            }
            else st = mij + 1;
        }

        if (w) D[++D[0]] = V[i].y;
        else D[st] = V[i].y;
    }
    return D[0];
}

int main()
{
    fin >> N;
    fin >> Ox >> Oy;
    for (long long xx, yy, i = 1; i <= N; i++)
    {
        fin >> xx >> yy;
        xx -= Ox;
        yy -= Oy;
        if (xx > 0 && yy > 0) C[1].push_back(make_pair(xx, yy));
        if (xx > 0 && yy < 0) C[2].push_back(make_pair(xx, -yy));
        if (xx < 0 && yy < 0) C[3].push_back(make_pair(-xx, -yy));
        if (xx < 0 && yy > 0) C[4].push_back(make_pair(-xx, yy));
    }

    for (long long i = 1; i <= 4; i++)
    {
        sort (C[i].begin(), C[i].end());
        sol += Afla_Numarul_Minim_De_Drumuri(C[i]);
    }

    fout << sol << '\n';
    fout.close();
    return 0;
}