Cod sursa(job #185875)

Utilizator victor_bla_blaDumitrescu Victor victor_bla_bla Data 26 aprilie 2008 12:19:35
Problema Piese Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1 kb
program piese3;
var a: array[1..500,1..500] of integer;
n,m,i,j,np: longint;
f: text;
procedure blabla(x1,y1,x2,y2: longint);
var p,min: integer;
begin
     if x2-x1<=y2-y1 then min:=x2-x1+1
     else min:=y2-y1+1;
     p:=1;
     while p<=min do
           p:=p*2;
     p:=p div 2;
     inc(np);
     for i:=x1 to x1+p-1 do
         for j:=y1 to y1+p-1 do
             a[i,j]:=np;
     if (x2-x1+1<>p) and (y2-y1+1<>p) then
     begin
          blabla(x1+p,y1,x2,y1+p-1);
          blabla(x1,y1+p,x2,y2);
     end;
     if (x2-x1+1=p) and (y2-y1+1<>p) then
        blabla(x1,y1+p,x2,y2);
     if (x2-x1+1<>p) and (y2-y1+1=p) then
        blabla(x1+p,y1,x2,y1+p-1);
end;
begin
     assign(f,'piese.in');
     reset(f);
     read(f,n,m);
     close(f);
     blabla(1,1,n,m);
     assign(f,'piese.out');
     rewrite(f);
     writeln(f,np);
     for i:=1 to n do
     begin
          for j:=1 to m do
              write(f,a[i,j],' ');
          writeln(f);
     end;
     close(f);
end.