记录编号 |
4575 |
评测结果 |
ATAAAAAAAA |
题目名称 |
填数 |
最终得分 |
90 |
用户昵称 |
zpl123 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
3.596 s |
提交时间 |
2008-10-20 22:15:15 |
内存使用 |
0.11 MiB |
显示代码纯文本
program tianshu;
type
type1=array[1..11,1..11] of integer;
type2=array[1..300] of boolean;
var
ans:type1;
f1,f2:type2;
n,tot:integer;
procedure init;
var
i,j:integer;
begin
assign(input,'tianshu.in');
reset(input);
assign(output,'tianshu.out');
rewrite(output);
readln(n);
close(input);
for i:=2 to n*n do
f1[i]:=true;
for i:=1 to 241 do f2[i]:=true;
ans[1,1]:=1;
for i:=2 to 241 do
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then f2[i]:=false;
end;
function ju(x,y,i:integer):boolean;
begin
ju:=false;
if x=1 then
begin
if y=1 then ju:=true
else if f2[ans[x,y-1]+i] then exit(true);
end
else
if y=1 then
begin
if f2[ans[x-1,y]+i] then exit(true) end
else if f2[ans[x,y-1]+i] and f2[ans[x-1,y]+i] then exit(true);
end;
procedure print;
var
i,j:integer;
begin
if tot=0 then
begin
writeln('NO');
close(output);
halt;
end
else
for i:=1 to n do
begin
for j:=1 to n-1 do
write(ans[i,j],' ');
writeln(ans[i,n]);
end;
close(output);
halt;
end;
procedure try(x,y:integer);
var
i,j:integer;
xx,yy:integer;
flag:boolean;
begin
if (x-1=n)and(y=1) then begin
inc(tot);
print;
end;
for i:=1 to n*n do
begin
if (f1[i]=true) then
begin
flag:=false;
flag:=ju(x,y,i);
if flag then
begin
ans[x,y]:=i;
f1[i]:=false;
xx:=x;
yy:=y+1;
if yy>n then
begin
xx:=x+1;
yy:=1;
end;
try(xx,yy);
f1[i]:=true;
ans[x,y]:=0;
end;
end;
end;
end;
begin
init;
if n=1 then
begin
writeln('NO');
close(output);
halt;
end;
try(1,2);
writeln('NO');
close(output);
end.