Cod sursa(job #1325451)

Utilizator cautionPopescu Teodor caution Data 23 ianuarie 2015 22:24:01
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <fstream>
#include <algorithm>
#include <list>
using namespace std;
struct box
{
    short x, y, z;
    long long vol;
    short no;
};
bool comp(box b1, box b2)
{
    if(b1.vol>b2.vol) return true;
    else return false;
}
int main()
{
    ifstream in("cutii.in");
    ofstream out("cutii.out");
    short n, t;
    box *boxes;
    list<short> lista;
    in>>n>>t;
    boxes=new box[n];
    for(short i=1; i<=t; ++i)
    {
        for(short j=0; j<n; ++j)
        {
            in>>boxes[j].x>>boxes[j].y>>boxes[j].z;
            boxes[j].vol = boxes[j].x*boxes[j].y*boxes[j].z;
        }
        sort(boxes, boxes+n, comp);
        lista.push_back(0);
        boxes[0].no=0;
        for(short i=1; i<n; ++i)
        {
            boxes[i].no=0;
            for(list<short>::iterator it=lista.begin(), ed=lista.end(); it!=ed; ++it)
            {
                if(boxes[i].x<boxes[*it].x&&boxes[i].y<boxes[*it].y&&boxes[i].z<boxes[*it].z)
                {
                     boxes[i].no=boxes[*it].no+1;
                     for(list<short>::iterator it=lista.begin(), ed=lista.end(); it!=ed; ++it)
                     {
                         if(boxes[*it].no<boxes[i].no)
                         {
                            lista.insert(it, i);
                            break;
                         }
                     }
                     break;
                }
            }
        }
        out<<boxes[*(lista.begin())].no+1<<endl;
    }
    in.close(); out.close();
    return 0;
}