比赛 NOIP_3 评测结果 WEAWWWAAAA
题目名称 填数 最终得分 50
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-09-12 21:58:32
显示代码纯文本
program tianshu;
var
  n,i,j,k,p:integer;
  sz,jz:array[0..100,0..100]of integer;
  table:array[0..10,0..10]of integer;
  hx:array[1..100]of integer;
procedure fill(x,y:integer);
var
  i2:integer;
begin
  if (x=n)and(y=n) then begin
    for j:=1 to n do
    begin
      for k:=1 to n do
        write(table[j,k]);
      writeln;
    end;
    close(input);
    close(output);
    halt;
  end
  else begin
    if y<n then begin
      for i2:=1 to sz[table[x,y],0] do
      begin
        if (jz[sz[table[x,y],i2],table[x-1,y+1]]=1)and(hx[sz[table[x,y],i2]]=0) then begin
          hx[sz[table[x,y],i2]]:=1;
          table[x,y+1]:=sz[table[x,y],i2];
          fill(x,y+1);
          table[x,y+1]:=0;
          hx[sz[table[x,y],i2]]:=0;
        end;
      end;
    end
    else begin
      for i2:=1 to sz[table[x,1],0] do
      begin
        if hx[sz[table[x,1],i2]]=0 then begin
          hx[sz[table[x,1],i2]]:=1;
          table[x+1,1]:=sz[table[x,1],i2];
          fill(x+1,1);
          table[x+1,1]:=0;
          hx[sz[table[x,1],i2]]:=0;
        end;
      end;
    end;
  end;
end;
begin
  assign(input,'tianshu.in');
  assign(output,'tianshu.out');
  reset(input);
  rewrite(output);
  readln(n);
  fillchar(sz,sizeof(sz),0);
  fillchar(jz,sizeof(jz),0);
  fillchar(hx,sizeof(hx),0);
  for i:=1 to n*n do
    for j:=1 to n*n do
    begin
      p:=0;
      if i<>j then begin
        for k:=2 to i+j-1 do
        begin
          if (i+j)mod k=0 then begin
            p:=1;
            break;
          end;
        end;
        if p=0 then begin
          sz[i,0]:=sz[i,0]+1;
          sz[i,sz[i,0]]:=j;
          jz[i,j]:=1;
          jz[j,i]:=1;
        end;
      end;
    end;
  table[1,1]:=1;
  hx[1]:=1;
  for i:=1 to n do
  begin
    jz[i,0]:=1;
    jz[0,i]:=1;
  end;
  fill(1,1);
  writeln('NO');
  close(input);
  close(output);
end.