Cod sursa(job #243129)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 11 ianuarie 2009 22:14:53
Problema Tablete Scor 70
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.52 kb
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 end else  begin pv:=vals +1; t:=pv-1 end;
//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; cont:=t ;
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; write(fout,a[i,j],' ');
                   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;
{
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.