Cod sursa(job #242994)

Utilizator nod_softwareBudisteanu Ionut Alexandru nod_software Data 11 ianuarie 2009 17:23:56
Problema Tablete Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.67 kb
program tablete;

{$APPTYPE CONSOLE}

uses
  SysUtils;
 var i,j,n,k,t: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;
for i:=1 to n do begin
for j:=1 to n do begin
                     if j=k then begin
                                   if b mod 2 =0 then begin
                                                                a[i,k]:=b ;use [b]:=1;
                                                           end  else begin
                                                                        a[i,k]:=b+1; use[b+1]:=1;
                                                                      end;
                                 end else begin
                                 while use[curent]=1 do inc(curent);
                                             a[i,j]:=curent;use [curent]:=1;inc(curent);
                                         end;
                 b:=b+1; 
                 end;
                 end;
                 k:=k+1;
 for i:=1  to n do begin
 for j:=k  to n do begin
                        if a[i,j]<a[i,j-1] then begin t:=a[i,j];
                                                       a[i,j]:=a[ i+1,1];
                                                       a[i+1,1]:=t;
                                                 end;
                   end;
                   end;
for i:=1 to n-1 do begin
for j:=1 to n do begin
                      write(fout,a[i,j],' ');
                 end; writeln(fout);
                 end;
close(fout);
end.