Pagini recente » Cod sursa (job #1883952) | Cod sursa (job #2686879) | Cod sursa (job #222717) | Cod sursa (job #2012413) | Cod sursa (job #223513)
Cod sursa(job #223513)
var f,g:text;
n,m,x,i,j:longint;
v:array[0..510,0..510]of longint;
procedure rez(l1,c1,l2,c2:longint);
var i,j,k,l,c,p:longint;
begin
if (l1<=l2)and(c1<=c2)then
begin
inc(x);
l:=l2-l1+1;
c:=c2-c1+1;
if (l<c)then k:=l else k:=c;
p:=1;
while (p<=k)do p:=p*2;
p:=p div 2;
for i:=l1 to l1+k-1 do
for j:=c1 to c1+k-1 do
v[i,j]:=x;
if (p>0)then
begin
rez(l1,c1+p,l1+p-1,c2);
rez(l1+p,c1,l2,c2);
end;
end;
end;
begin
assign(f,'piese.in');
assign(g,'piese.out');
reset(f);
rewrite(g);
read(f,n,m);
rez(1,1,n,m);
writeln(g,x);
for i:=1 to n do
begin
for j:=1 to m do write(g,v[i,j],' ');
writeln(g);
end;
close(f);
close(g);
end.