Pagini recente » Cod sursa (job #1244709) | Cod sursa (job #1866285) | Cod sursa (job #2339110) | Cod sursa (job #474218) | Cod sursa (job #243651)
Cod sursa(job #243651)
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
pv:=pv-2*(n-1);
curent:=1; cont:=t ;
for i:=1 to n do begin a[i,k]:=pv ;
use [pv]:=1;
pv:=pv+2 ;
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
//write(fout,a[i,k],' ');
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;
if a[1,k+1]=a[n,k] then begin a[1,k+1]:=a[1,k+1]-1 ;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.