记录编号 2308 评测结果 AWAAAAAAAA
题目名称 填数 最终得分 90
用户昵称 Gravatarelysian 是否通过 未通过
代码语言 Pascal 运行时间 2.500 s
提交时间 2008-09-17 21:36:34 内存使用 0.11 MiB
显示代码纯文本
program yuffie;
const
fin='tianshu.in';fout='tianshu.out';
var
sushu:set of byte;
f1,f2:text;
used:array[1..101] of boolean;
ans:array[0..10,0..10] of integer;
f:boolean;
n:longint;

procedure init;
begin
assign(f1,fin);reset(f1);
readln(f1,n);
close(f1);
sushu:=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199];
ans[1,1]:=1;
assign(f2,fout);rewrite(f2);
end;

procedure print;
var
i,j:longint;
begin
for i:=1 to n do
for j:=1 to n do
if j<n then write(f2,ans[i,j],' ')
else writeln(f2,ans[i,j]);
f:=true;
end;

procedure search(x,y:integer);
var
i:integer;
flag:boolean;
begin
if (x=n)and(y>n) then print;
if f=false then
begin
 if y<=n then
  for i:=2 to n*n do
   begin
    flag:=false;
    if (used[i]=false) then
     begin
     if x=1 then if (i+ans[x,y-1]) in sushu then flag:=true;
     if y=1 then if (i+ans[x-1,y]) in sushu then flag:=true;
     if ((i+ans[x-1,y]) in sushu)and((i+ans[x,y-1]) in sushu) then flag:=true;
       if flag=true then
       begin
        ans[x,y]:=i;
        used[i]:=true;
        search(x,y+1);
        used[i]:=false;
        end;
       end;

 end
 else search(x+1,1);

end;

end;


BEGIN
init;
f:=false;
if n>1 then search(1,2);
if f=false then writeln(f2,'NO');
close(f2);
end.