Cod sursa(job #2282697)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 14 noiembrie 2018 13:09:11
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f ("cutii.in");
ofstream g ("cutii.out");

struct cutie
{
    int x, y, z;
};

cutie gigel[3505];

int n, T, vf;

int sti[3505];

bool cmp (cutie a, cutie b)
{
    if (a.x > b.x) return false;

    if (a.x == b.x && a.y > b.y) return false;

    if (a.x == b.x && a.y == b.y && a.z > b.z) return false;

    return true;
}

bool verif (int a, int b)
{
    if (gigel[a].x < gigel[b].x && gigel[a].y < gigel[b].y && gigel[a].z < gigel[b].z) return true;

    return false;
}

int cautbin (int cut)
{
    int st = 1, dr = vf;
    int poz = 0;

    while (st <= dr)
    {
        int mij = (st + dr) / 2;

        if (verif(sti[mij], cut) == true)
        {
            poz = mij;
            st = mij + 1;
        }
        else
        {
            dr = mij - 1;
        }
    }

    return poz;
}
int main()
{
    f >> n >> T;

    for (; T; T--)
    {
        for (int i = 1; i <= n; i++)
        {
            f >> gigel[i].x >> gigel[i].y >> gigel[i].z;
        }

        sort(gigel + 1, gigel + n + 1, cmp);
        vf = 0;

        for (int i = 1; i <= n; i++)
        {
            int poz = cautbin(i);

            if (poz == vf)
            {
                vf++;
                sti[poz] = i;
            }
            else
            {
                sti[poz+1] = i;
            }
        }

        g << vf << '\n';
    }
    return 0;
}