比赛 NOIP_3 评测结果 WTWWWWWWWA
题目名称 填数 最终得分 10
用户昵称 辨机ZN 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-19 10:04:00
显示代码纯文本
program tianshu(f1,f2);
 type
  zn=array [1..1000] of integer;
  la=array [1..1000] of boolean;
  ka=array [0..10,0..10] of integer;
 var
  ss:zn; f1,f2:text; i,j,k,m,n,ll:longint;
  flag:la; c:ka; ssf:la;
 procedure zhishu;
  var
   i,j,k,p:longint; flag:boolean;
  begin
   ss[1]:=2; ss[2]:=3;
   ll:=2; ssf[2]:=true; ssf[3]:=true;
   for i:=5 to 1000 do
    begin
    flag:=true;
    for j:=2 to trunc(sqrt(i)) do
      if i mod j=0 then begin flag:=false; break; end;
    if flag then begin inc(ll); ss[ll]:=i; ssf[i]:=true; end;
    end;
 end;
 procedure print(mm:ka);
  var i,j,k,p:longint;
   begin
    for i:=1 to n do
     begin
     for j:=1 to n do
      write(f2,mm[i,j],' ');
      writeln(f2);
     end;
     close(f1); close(f2); halt;
    end;
 procedure search(x,y:integer; map:ka; flagm:la);
  var
   i,j,k,p,l:longint;
  begin
     for i:=2 to ss[ll] do
      if ((x=1)or(ssf[map[x-1,y]+i]))and((y=1)or(ssf[map[x,y-1]+i]))and(flagm[i])
       then
        begin
         map[x,y]:=i; flagm[i]:=false;
         if (x=n)and(y=n) then print(map);
         if (x<>n)and(y=n) then search(x+1,1,map,flagm)
                           else if (x<>n)or(y<>n) then search(x,y+1,map,flagm);
        end;
  end;



 begin
  assign(f1,'tianshu.in'); reset(f1);
  assign(f2,'tianshu.out'); rewrite(f2);
  readln(f1,n);
  if n=1 then begin writeln(f2,1); close(f1); close(f2); halt; end;
  zhishu;
  for i:=1 to 1000 do flag[i]:=true;
  c[1,1]:=1; flag[1]:=false;
  for i:=1 to n do begin c[i,0]:=0; c[0,i]:=0; end;
  search(1,2,c,flag);
  writeln(f2,'NO');
  close(f1);
  close(f2);
 end.