比赛 2008haoi模拟训练1 评测结果 AWWWWAWWAA
题目名称 分组 最终得分 40
用户昵称 SMXX 运行时间 0.004 s
代码语言 Pascal 内存使用 0.20 MiB
提交时间 2008-04-22 11:29:00
显示代码纯文本
program dataa;
var
f1,f2:text;
k,x,y,l,f,h,g,n,m,sum,i,j:integer;
a:array[1..6]of 1..20;
c:array[1..625,1..6]of 1..20;
begin
assign(f1,'dataa.in');
assign(f2,'dataa.out');
reset(f1);
rewrite(f2);
readln(f1,n,m);
sum:=1;
k:=n div m;
if m= 2 then begin writeln(f2,(n-1));for i:= 1 to n-1 do writeln(f2,i,' ',n-i);end
        else begin
for i:= 1 to k do  begin
 for j:= 1 to m-1 do  a[j]:=i;
 a[m]:=n-i*(m-1);
  x:=m-1;
 for y:= 1to m do c[sum,y]:=a[y];
 inc(sum);
  f:=-1;
  while f=-1 do begin
 for l:=x downto 2 do
   while (a[l]+1)<=(a[l+1]-1) do  begin inc(a[l]);dec(a[l+1]);
                                  for h:= 1to m do c[sum,h]:=a[h];
                                  inc(sum);
                                    end;

dec(x);
if x=1 then f:=1;
end;end;
writeln(f2,(sum-1));
for i:= 1to sum-1 do begin
 for j:= 1to m-1 do write(f2,c[i,j],' ');
 writeln(f2,c[i,m]);
 end;end;
close(f1);
close(f2);
 end.