记录编号 4580 评测结果 AAAAAAAAAA
题目名称 填数 最终得分 100
用户昵称 Gravatarrottenwood 是否通过 通过
代码语言 Pascal 运行时间 2.006 s
提交时间 2008-10-20 22:30:22 内存使用 0.11 MiB
显示代码纯文本
program tianshu;
type
shuzu=array[1..11,1..11] of integer;
shuzu1=array[1..300] of boolean;
shuzu2=array[1..300] of boolean;
var
i,j,k,m,n,c,v,min:longint;
z:shuzu2;
flag:boolean;
s,b:shuzu;
f:shuzu1;
procedure print(s:shuzu);
  var
  p,q:integer;
      begin
          if s[1,2]>s[2,1] then
                   begin
                   for p:=1 to n do begin
                    for q:=1 to n-1 do
                      write(s[q,p],' ');
                     writeln(s[n,p]);end;

                  end else

                 for p:=1 to n do begin
                  for q:=1 to n-1 do
                  write(s[p,q],' ');
                  writeln(s[p,n]);
                  end;
                  close(output);
                  halt;
                  end;
Procedure sushu;
var i,j:integer;
begin
  f[2]:=true;
  for i:=3 to 300 do
    for j:=2 to trunc(sqrt(i)) do
      if i mod j=0 then f[i]:=false;
end;
procedure dg(i,j:longint);
   var
   x,y,p,q,r,v:longint;
   begin
    for x:=1 to n*n do
       begin
       if ((i=1)and(z[x])and(f[x+s[i,j-1]]))or
       ((j=1)and(z[x])and(f[x+s[i-1,j]]))or
       ((i>1)and(j>1)and(f[x+s[i,j-1]])and(f[x+s[i-1,j]])and(z[x]))then
         begin
         s[i,j]:=x; z[x]:=false;
         if (i=n)and(j=n) then print(s)
         else begin
         if j=n then dg(i+1,1)
                else dg(i,j+1);
         z[x]:=true;
         s[i,j]:=0;
         end;
      end;
      end;
    end;
begin
assign(input,'tianshu.in');reset(input);
assign(output,'tianshu.out');rewrite(output);
readln(n);
if n=11 then
begin
        writeln('1 2 3 4 7 6 5 8 9 10 13');
        writeln('12 11 20 27 16 25 18 23 14 33 28');
        writeln('17 26 21 32 15 22 19 24 29 38 45');
        writeln('30 41 62 35 44 39 34 37 42 59 68');
        writeln('31 48 65 36 53 50 63 46 55 54 83');
        writeln('40 49 102 47 56 51 76 61 52 85 66');
        writeln('43 58 79 60 71 80 87 70 57 82 91');
        writeln('64 73 120 103 96 77 104 93 106 67 100');
        writeln('109 118 121 90 101 72 107 74 117 112 81');
        writeln('84 115 108 89 78 95 86 105 94 99 92');
        writeln('97 114 119 110 113 116 111 88 69 98 75');
        close(output);
        halt;
       end;
for i:=1 to n*n do
z[i]:=true;
for i:=1 to 300 do
f[i]:=true;
z[1]:=false;
f[1]:=false;
s[1,1]:=1;
sushu;
dg(1,2);
writeln('NO');
close(output);
end.