Cod sursa(job #442695)

Utilizator dushmiMihai-Alexandru Dusmanu dushmi Data 14 aprilie 2010 23:17:46
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include<cstdio>
#include<algorithm>
using namespace std;
struct cub
{
	int x,y,z;
};
cub a[1<<12];
int n,t,v[1<<12];
bool comp(const cub &A,const cub &B)
{
	if(A.x>B.x) return false;
	if(A.x<B.x) return true;
	if(A.y>B.y) return false;
	if(A.y<B.y) return true;
	if(A.z>B.z) return false;
	if(A.z<B.z) return true;
	return true;
}
int cautb(int poz)
{
	int i=0,pas=1<<12;
	for(i=0;pas;pas>>=1)
		if(i+pas<=v[0] && a[v[i+pas]].x<a[poz].x && a[v[i+pas]].y<a[poz].y && a[v[i+pas]].z<a[poz].z)
			i+=pas;
	return i+1;
}
int main()
{
	freopen("cutii.in","r",stdin);
	freopen("cutii.out","w",stdout);
	scanf("%d%d",&n,&t);
	for(;t>=1;t--)
	{
		for(int i=1;i<=n;i++)
			scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
		sort(a+1,a+n+1,comp);
		v[0]=1;
		v[1]=1;
		for(int i=2;i<=n;i++)
		{
			int j=cautb(i);
			if(j>v[0])
				++v[0];
			v[j]=i;
		}
		printf("%d\n",v[0]);			
	}
	return 0;
}