Cod sursa(job #1327991)

Utilizator jordasIordache Andrei Alexandru jordas Data 27 ianuarie 2015 19:19:13
Problema Cutii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <fstream>
#include <cstdlib>

using namespace std;

 ifstream x ("cutii.in");
 ofstream y ("cutii.out");

 struct struct1
 {
     int l;
     int w;
     int h;
 };

 int n,t;
 int boxing[3501];
 struct1 box[3501];

 void quicksort(struct1 box[],int l, int r)
 {
     int i,j;
     int p;
     struct1 aux,pivot;

     p=rand()%(r-l+1)+l;

     aux=box[l];
     box[l]=box[p];
     box[p]=aux;

     pivot=box[l];

     p=l;
     i=l+1;

     for(j=l+1;j<=r;j++)
        if(pivot.l<box[j].l)
        {
            aux=box[j];
            box[j]=box[i];
            box[i]=aux;

            i++;
        }

    aux=box[p];
    box[p]=box[i-1];
    box[i-1]=aux;

    if(l<i-2)
       quicksort(box,l,i-2);
    if(i<r)
       quicksort(box,i,r);
 }

int main()
{
    int i,j,k;

    x>>n>>t;

    int maxB;

    for(k=1;k<=t;k++)
    {
        maxB=0;

        for(i=1;i<=n;i++)
           x>>box[i].l>>box[i].w>>box[i].h;

        quicksort(box,1,n);

        for(i=1;i<=n;i++)
           boxing[i]=1;

        for(i=1;i<=n-1;i++)
           for(j=i+1;j<=n;j++)
              if(box[i].l>box[j].l && box[i].w>box[j].w && box[i].h>box[j].h)
                 boxing[j]=boxing[i]+1;

        for(i=1;i<=n;i++)
           maxB=max(maxB,boxing[i]);

        y<<maxB<<'\n';
/*
        for(i=1;i<=n;i++)
        {
            y<<box[i].l<<" "<<box[i].w<<" "<<box[i].h;
            y<<'\n';
        }
        y<<'\n';
*/
    }
    return 0;
}