Cod sursa(job #719843)

Utilizator repp4raduRadu-Andrei Szasz repp4radu Data 22 martie 2012 09:34:58
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.84 kb
#include <fstream>
#include <algorithm>
#include <vector>

#define MAX 3550

using namespace std;

int n;

struct cutie
{
    int x, y, z;
    void operator=(const cutie a)
    {
        this->x = a.x; this->y = a.y; this->z = a.z;
    }
    bool operator<(const cutie a) const
    {
        return ((this->x < a.x) && (this->y < a.y) && (this->z < a.z));
    }
    bool operator>(const cutie a) const
    {
        return ((this->x > a.x) || (this->y > a.y) || (this->z > a.z));
    }
    bool operator<=(const cutie a) const
    {
        if(this->y < a.y)
            return true;
        else if(this->y == a.y)
            return this->x < a.x;
        return false;
    }
}v[MAX];

bool cmp(cutie a, cutie b)
{
    if(a.z < b.z)
        return true;
    else
    {
        if(a.z == b.z)
        {
            if(a.y < b.y)
                return true;
            else
                if(a.y == b.y)
                    return a.x < b.x;
        }
    }
    return false;
}

int subsirCrescator()
{
    vector<cutie> b; cutie add; add.x = 0, add.y = 0, add.z = 0;
    vector<cutie>::iterator it, it2;
    b.push_back(add);
    int i;
    for(i = 1; i <= n; i++)
    {
        it = upper_bound(b.begin(), b.end(), v[i]);
        it2 = it; it2--;
        while((*it2) > v[i])
            it2--;
        it2++;
        if(it2 == b.end())
            b.push_back(v[i]);
        else
            if((*it2) <= v[i])
                (*it2) = v[i];
    }
    return b.size() - 1;
}

int main()
{
    ifstream in("cutii.in");
    ofstream out("cutii.out");
    int t;
    in>>n>>t;
    while(t--)
    {
        for(int i = 1; i <= n; i++)
        {
            in>>v[i].x>>v[i].y>>v[i].z;
        }
        sort(v + 1, v + n + 1, cmp);
        out<<subsirCrescator()<<'\n';
    }
    return 0;
}