Cod sursa(job #47349)

Utilizator arenakadaffKadaff arenakadaff Data 3 aprilie 2007 16:47:48
Problema Cutii Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.45 kb
#include <stdio.h>


struct cut{
int x , y , z ; } tab[3500] ;

long long v[3500] ;
int c[3500] ;


int cmp(struct cut a , struct cut b)
{
	if(a.x < b.x) return 1 ;
	if(a.x > b.x) return 0 ;
	if(a.y < b .y) return 1 ;
	if(a.y > b.y) return 0 ;
	if(a.z <= b.z) return 1 ;
	return 0 ;
}


int divide(int p , int q)
{
	int st = p , dr = q ;
	struct cut x = tab[p] ;
	while(st < dr)
	{
		while(st < dr && cmp(tab[dr] , x)) dr-- ;
		tab[st] = tab[dr] ;
		while(st < dr && !cmp(tab[st] , x)) st++ ;
		tab[dr] = tab[st] ;
	}
	tab[st] = x ;
	return st ;
}


void quicksort(int p , int q)
{
	int m = divide(p , q) ;
	if(m-1 > p) quicksort(p , m-1) ;
	if(m + 1 < q) quicksort(m+1 , q) ;
}

int main()
{
	int i , j , t , n , max ;
	FILE *in , *out ;
	in = fopen("cutii.in" , "rt") ;
	out = fopen("cutii.out" , "wt") ;
	fscanf(in , "%d %d" , &n , &t) ;
	while(t--)
	{
		for(i = 0 ; i < n ; i++)
		{
			fscanf(in , "%d %d %d" , &tab[i].x , &tab[i].y , &tab[i].z) ;
			v[i] = tab[i].x * tab[i].y * tab[i].z ;
		}
		quicksort(0 , n-1) ;
		for(i = 0 ; i < n ; i++) c[i] = 1 ;
		max = 0 ;
		for(i = n - 2 ; i >= 0 ; i--) for(j = i + 1 ; j < n ; j++) if((tab[i].x > tab[j].x && tab[i].y > tab[j].y && tab[i].z > tab[j].z) && (c[i] < c[j] + 1))
		{
			c[i] = c[j] + 1 ;
			if(c[i] > max) max = c[i] ;
		}
		if(n==1) fprintf(out , "1\n") ;
		else fprintf(out , "%d\n" , max) ;
	}
	fclose(in) ;
	fclose(out) ;
	return 0 ;
}