Cod sursa(job #1268177)

Utilizator PatrunjeluMarginean Bogdan Alexandru Patrunjelu Data 20 noiembrie 2014 17:55:53
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.64 kb
#include <vector>
#include <algorithm>
#include <fstream>
#include <cassert>

const int MaxBoxes = 4000;

struct Box
{
    int width;
    int length;
    int height;
};

std::vector<Box> Boxes;
int Lengths[MaxBoxes];

bool CompareBoxesByHeight(const Box& boxA, const Box& boxB)
{
    return boxA.height < boxB.height;
}

int main()
{
    int tests = 0;
    int boxCount = 0;
    std::ifstream inFile("cutii.in");
    std::ofstream outFile("cutii.out");
    inFile >> boxCount;
    inFile >> tests;
    Boxes.resize(boxCount);
    for (int n = 0; n < tests; ++n)
    {
        int maxChain = 0;
        Boxes.clear();
        std::fill(Lengths, Lengths + MaxBoxes, 0);
        for (int m = 0; m < boxCount; ++m)
        {
            Box box;
            inFile >> box.length;
            inFile >> box.width;
            inFile >> box.height;
            Boxes[m] = box;
        }
        std::sort(Boxes.begin(), Boxes.end(), &CompareBoxesByHeight);
        for (int i = boxCount - 1; i >= 0; --i)
        {
            for (int j = i + 1; j < boxCount; ++j)
            {
                if ((Boxes[i].width < Boxes[j].width) && (Boxes[i].length < Boxes[j].length) && (Lengths[i] < Lengths[j] + 1))
                {
                    Lengths[i] = Lengths[j] + 1;
                }
            }
            if (Lengths[i] == 0)
            {
                Lengths[i] = 1;
            }
            if (Lengths[i] > maxChain)
            {
                maxChain = Lengths[i];
            }
        }
        outFile << maxChain << std::endl;
    }
    outFile.close();
    inFile.close();
    return 0;
}