Pagini recente » Cod sursa (job #1661347) | Cod sursa (job #1329345) | Cod sursa (job #1715894) | Cod sursa (job #1065774) | Cod sursa (job #243058)
Cod sursa(job #243058)
program tablete;
{$APPTYPE CONSOLE}
uses
SysUtils;
var i,j,n,k,t,pv ,vals:integer;fin,fout:text; b,curent:longint;
a:array [1..1000,1..1000] of integer;
use:array [1..1000001] of byte;
begin
assign (fin,'tablete.in');reset(fin);
assign(fout,'tablete.out');rewrite(fout);
readln(fin,n,k);
b:=1 ; curent:=1;
//calculam val dupa colana (n-k)*n buc in stanga
//n pe col k val apare de la n*n -val stanga
vals :=n*n-(n-k)*n ;
//calc prima val ...
if vals mod 2=0 then pv:=vals else pv:=vals +1; t:=pv;
//afisam col cu val pare
for i:=1 to n do begin a[i,k]:=pv ;
use [pv]:=1;
;pv:=pv-2;
end;
curent:=1;
for i:=n downto 1 do begin
for j:=1 to k-1 do begin
if use[curent]=1 then inc (curent);
a[i,j]:=curent;curent:=curent+1;
end;
end;
for i:=n downto 1 do begin
for j:=k+1 to n do begin
if use[curent]=1 then inc (curent);
a[i,j]:=curent;curent:=curent+1;
end;
end;
for i:=1 to n do begin
for j:=1 to n do begin
write(fout,a[i,j],' ');
end; writeln(fout);
end;
close(fout);
end.