Cod sursa(job #769619)

Utilizator lily3Moldovan Liliana lily3 Data 20 iulie 2012 11:18:53
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
 #include<fstream>
 #include<algorithm>
 using namespace std;
 
 int i,j,n,m,l[3501],t,max1,rez,p[3501],best[3501],poz,nr;
 struct dim
 {
	int x,y,z;
 };
 dim a[3501];
 bool cmp(dim a,dim b)
 {
	return a.x<b.x;
 }
 int compara(int i,dim poz)
 {
	if(a[i].x<poz.x&&a[i].y<poz.y&&a[i].z<poz.z)
		return 1;
	return 0;
 }
 int cauta(dim poz)
 {
	int mij,st=0,dr=nr;
	mij=(st+dr)/2;
	while(st<=dr)
	{
		
		if(compara(mij,poz)&&!compara(mij+1,poz))
			return mij;
		else
			if(compara(mij+1,poz))
				st=mij+1,mij=(st+dr)/2;
			else
				dr=mij-1,mij=(st+dr)/2;
	}
	return nr;
 }
 int main()
 {
	freopen("cutii.in","r",stdin);
	freopen("cutii.out","w",stdout);
	scanf("%d%d",&n,&t);
	while(t--)
	{
		for(i=1;i<=n;++i)
			scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
		l[n]=1;
		max1=0,rez=0;
		sort(a+1,a+n+1,cmp);
		nr=best[1]=l[1]=1;
		l[0]=0;
		rez=1;
		for(i=2;i<=n;++i)
		{
			poz=cauta(a[i]);
			best[i]=poz+1;
			p[i]=l[poz];
			l[poz+1]=i;
			if(nr<poz+1)
				nr=poz+1;
			if(rez<best[i])
				rez=best[i];
		}
		printf("%d\n",rez);
	}
	return 0;
 }