Cod sursa(job #167660)

Utilizator tamas_iuliaTamas Iulia tamas_iulia Data 29 martie 2008 21:36:33
Problema Piese Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.89 kb
const p2 : array[1..10] of integer=(1,2,4,8,16,32,64,128,256,501);
var a : array[1..500,1..500] of integer;
    i,j,n,m,nr : longint;
    f,g : text;
procedure umple(x1,y1,x2,y2:integer);
var i,j,c,latx,laty,lat_min : integer;
begin
if (x1<=n)and(x2<=n)and(y1<=m)and(y2<=m)then
if (x1<=x2) and (y1<=y2) then
begin
  latx:=x2-x1+1;
  laty:=y2-y1+1;
  lat_min:=latx;
    if laty<lat_min then lat_min:=laty;
  j:=1;
    while (p2[j]<=lat_min)and(j<=9)
      do  inc(j);
  dec(j);
    inc(nr);
    for i:=x1 to x1+p2[j]-1 do
        for c:=y1 to y1+p2[j]-1 do
            a[i,c]:=nr;
  umple(x1,y1+p2[j],x1+p2[j]-1,y2);
  umple(x1+p2[j],y1,x2,y2);
end;
end;

begin
assign(f,'piese.in');reset(f);
assign(g,'piese.out');rewrite(g);
read(f,n,m);
umple(1,1,n,m);
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.