Cod sursa(job #243054)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 11 ianuarie 2009 18:51:56
Problema Tablete Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.35 kb
program tablete;

{$APPTYPE CONSOLE}

uses
  SysUtils;
 var i,j,n,k,t,pv ,vals:integer;fin,fout:text; b,curent:longint;
 a:array [1..10,1..10] 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.