记录编号 |
4700 |
评测结果 |
ATAAATTTTA |
题目名称 |
填数 |
最终得分 |
50 |
用户昵称 |
bly1991 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
10.047 s |
提交时间 |
2008-10-22 13:04:49 |
内存使用 |
0.11 MiB |
显示代码纯文本
program bly(input,ouput);
type
t1=array[0..11,0..11] of integer;
t2=array[1..300] of boolean;
var
a:array[1..300] of boolean;
b:t2;
n,i,j,num:integer;
sh:t1;
f1,f2:text;
function pd(x,y,z:integer;g:t1):boolean;
begin
pd:=false;
if (x=1)and(g[x,y-1]+z mod 2<>0) then pd:=true;
if (y=1)and(g[x-1,y]+z mod 2<>0) then pd:=true;
if (x<>1)and(y<>1)and((g[x-1,y]+g[x,y-1]) mod 2=0) then pd:=true;
end;
procedure print(g:t1);
var
i0,j0:integer;
begin
inc(num);
for i0:=1 to n do begin
for j0:=1 to n do begin
write(f2,g[i0,j0],' ');
end;
writeln(f2);
end;
close(f2);
halt;
end;
procedure dg(x,y:integer;g:t1);
var
i0,j0:integer;
p1,p2:boolean;
temp:t1;
temp0:t2;
begin
temp:=g; temp0:=b;
for i0:=2 to n*n do begin
p1:=a[g[x-1,y]+i0];
p2:=a[g[x,y-1]+i0];
if x=1 then p1:=true; if y=1 then p2:=true;
if (p1)and(p2)and(b[i0]=false)and(pd(x,y,i0,g)) then begin
b[i0]:=true;
g[x,y]:=i0;
if (y=n)and(x=n) then print(g)
else begin
if y=n then dg(x+1,1,g) else dg(x,y+1,g);
end;
end;
g:=temp; b:=temp0;
end;
end;
begin
for i:=2 to 300 do a[i]:=true;
for i:=2 to 300 do begin
for j:=2 to trunc(sqrt(i)) do begin
if i mod j=0 then a[i]:=false;
end;
end;
assign(f1,'tianshu.in');
reset(f1);
readln(f1,n);
close(f1);
for i:=1 to 100 do b[i]:=false;
sh[1,1]:=1; b[1]:=true;
assign(f2,'tianshu.out');
rewrite(f2);
dg(1,2,sh);
if num=0 then writeln(f2,'NO');
close(f2);
end.