Cod sursa(job #128393)

Utilizator TudorutzuMusoiu Tudor Tudorutzu Data 27 ianuarie 2008 00:20:05
Problema Piese Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.18 kb
type mtr=array[1..500,1..500] of longint;
var f,g:text;
    a:mtr;
    nr,i,j,n,m:longint;
procedure piese(x,y:longint; var nr:longint);
var j,k,i,min:longint;
begin
     if x>y then min:=y
            else min:=x;
     i:=0;
     while 1 shl i< min do inc(i);
     dec(i);    inc(nr);
     for j:=x to x+(1shl i)-1 do
          for k:=y to y+(1shl i)-1 do a[i,j]:=nr;
     if n-y>1 then piese(x+(1shl i),y,nr)
              else
               if (n-y=1)and(m-x<=1) then
                    for k:=1 to m do
                    begin
                         inc(nr);
                         a[n,k]:=nr;
                    end;
     if m-x>1 then piese(x,y+(1shl i),nr)
              else
               if (m-x=1)and(n-y<=1) then
                    for k:=1 to n do
                    begin
                         inc(nr);
                         a[k,m]:=nr;
                    end;
end;
begin
     assign(f,'piese.in'); reset(F);
     assign(g,'piese.out'); rewrite(g);
     readln(f,n,m);
     nr:=0;
     piese(1,1,nr);
     for i:=1 to n do
     begin
          for j:=1 to m do write(g,a[i,j],' ');
          writeln(g);
     end;
     close(g);
end.