Pagini recente » Cod sursa (job #2915327) | Cod sursa (job #1068335) | Cod sursa (job #559164) | Cod sursa (job #727706) | Cod sursa (job #243243)
Cod sursa(job #243243)
program tablete;
{$APPTYPE CONSOLE}
uses
SysUtils;
var i,j,n,k:integer;fin,fout:text; t,pv ,vals,b,curent,cont:longint;
a:array [1..1000,1..1000] of longint;
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 begin pv:=vals;t:=pv+1 end else begin pv:=vals +1; t:=pv end;
//afisam col cu val pare
for i:=n downto 1 do begin a[i,k]:=pv ;
use [pv]:=1;
pv:=pv-2;
end;
curent:=1; cont:=t ;
for i:=1to n do begin
for j:=k+1 to n do begin
// if use[cont]=1 then inc (cont);
a[i,j]:=cont;cont:=cont+1;
// write(fout,a[i,j],' ');
end;
// writeln(fout);
end;
for i:=1 to n do begin
for j:=1 to k-1 do begin
if use[curent]=1 then inc (curent);
a[i,j]:=curent;curent:=curent+1; //write(fout,a[i,j],' ');
end;
// end;
//for i:=n downto 1 do begin
// write(fout,a[i,k],' ');
end;
if a[1,k+1]=a[n,k] then a[1,k+1]:=a[1,k+1]-1;
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.