Cod sursa(job #340323)

Utilizator doruletzPetrican Teodor doruletz Data 14 august 2009 11:29:24
Problema Tablete Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.24 kb
program x;
var n,k:0..1000;
      i,j,cont,a:0..1000000;
    m:array[0..1000,0..1000]of 0..1000000;
    t:text;
begin
 assign(t,'tablete.in'); reset(t);
 readln(t,n,k);
 close(t);
 if (k mod 2)=0 then
        begin
         cont:=0;
         for i:=1 to n do
          for j:=1 to k do begin
           inc(cont);
           m[i,j]:=cont;
          end;

         for i:=1 to n do
          for j:=k+1 to n do begin inc(cont); m[i,j]:=cont; end;
        end
 else
        begin
         cont:=0;
         for i:=1 to n do begin
           for j:=1 to k do begin
            inc(cont);
            m[i,j]:=cont;
            if (j=k)and(i mod 2<>0) then m[i,j]:=cont+1;
            if (j=1)and(i mod 2=0) then m[i,j]:=cont-1;
           end;
         end;

         if (n mod 2)=0 then
          for i:=1 to n do
           for j:=k+1 to n do begin inc(cont); m[i,j]:=cont; end;

         a:=cont;
         if (n mod 2)<>0 then begin
          for i:=1 to n do
           for j:=k+1 to n do begin inc(cont); m[i,j]:=cont; end;
          m[1,k+1]:=a-1;
         end;
        end;

 assign(t,'tablete.out'); rewrite(t);
 for i:=1 to n do begin
  for j:=1 to n do write(t,m[i,j],' ');
  writeln(t);
 end;
 close(t);
end.