Cod sursa(job #128402)

Utilizator TudorutzuMusoiu Tudor Tudorutzu Data 27 ianuarie 2008 00:53:39
Problema Piese Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.85 kb
type mtr=array[1..500,1..500] of longint;
var f,g:text;
    a:mtr;
    nr,i,j,n,m:longint;
procedure piese(x1,y1,x2,y2:longint;var nr:longint);
var j,k,i,min:longint;
begin
     if x2-x1+1>y2-y1+1 then min:=y2-y1+1
                        else min:=x2-x1+1;
     i:=0;
     while 1 shl i< min do inc(i);
     dec(i);      inc(nr);
     for j:=x1 to x1+(1shl i)-1 do
          for k:=y1 to y1+(1shl i)-1 do a[k,j]:=nr;
     if x1+(1shl i)-1<=m then piese(x1,y1+(1shl i)-1,x1+(1shl i)-1,y2,nr);
     if y2<=n then piese(x1+(1shl i)-1,y1,x2,y2,nr);
end;
begin
     assign(f,'piese.in'); reset(F);
     assign(g,'piese.out'); rewrite(g);
     readln(f,n,m);
     nr:=0;
     piese(1,1,m,n,nr);
     writeln(g,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.