Cod sursa(job #1178889)

Utilizator vasica38Vasile Catana vasica38 Data 27 aprilie 2014 14:35:07
Problema Cutii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.06 kb
program p1;
 type cutie=record
 x,y,z:longint;
   end;
var a:array[0..3500] of cutie;
    v:array[0..3500] of longint;
    f,g:text;
    b1,b2:array[0..1 shl 17] of char;
    i,n,j,k,u,m,t,ic,sf,poz:longint;


function cauta(x:longint) : longint;
var mijl:longint;
begin
 ic:=1;
 sf:=k;
  while ic<=sf do begin
        mijl:=(ic+sf) div 2;
        if x<v[mijl] then sf:=mijl-1
                else ic:=mijl+1;
                 end;
  cauta:=ic;
end;



function compara(o1,o2:cutie):longint;
begin
if o1.x<o2.x then exit (-1);
if o1.x>o2.x then exit (1);
if o1.y<o2.y then exit (1);
if o1.y>o2.y then exit (-1);
if o1.z<o2.z then exit (1);
if o1.z>o2.z then exit (-1);
exit (0);
end;
procedure quick(left,right:longint);
var i,j:longint;
    x,y:cutie;
begin
 i:=left;
 j:=right;
 x:=a[(left+right) div 2];

 repeat
  while compara(a[i],x)<0 do inc(i);
  while compara(a[j],x)>0 do dec(J);
   if i<=j then begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(I);
                dec(J);
                end;
  until i>j;
  if left<j then quick(left,j);
  if i<right then quick(i,right);
end;
begin
assign(f,'cutii.in');reset(F);
assign(g,'cutii.out');rewrite(G);
settextbuf(F,b1);
settextbuf(g,b2);
readln(f,n,t);
for u:=1 to t do begin
        for i:=1 to n do begin
                 readln(f,a[i].x,a[i].y,a[i].z);
                 v[i]:=0;
                        end;
        quick(1,n);
       { for i:=1 to n do writeln(g,a[i].x,' ',a[i].y,' ',a[i].z); }
       k:=0;
       for i:=0 to n-1 do
                begin
                 v[i]:=1;
                 for j:=i-1downto  0do
                  if (v[i]<v[j]+1) and ((a[i].x>a[j].x) and (a[i].y>a[j].y) and (a[i].z>a[j].z)) then v[i]:=v[j]+1;
                 if v[i]>k then k:=v[i];
                end;


       {for i:=1 to n do begin
        poz:=cauta(a[i].z);
        v[poz]:=a[i].z;
        if poz>k then k:=poz;
                end;  }
        writeln(g,k);
                end;
close(F);
close(G);
end.