记录编号 |
4577 |
评测结果 |
AAAAAAAAAA |
题目名称 |
填数 |
最终得分 |
100 |
用户昵称 |
打不死的羊 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
1.989 s |
提交时间 |
2008-10-20 22:21:06 |
内存使用 |
0.11 MiB |
显示代码纯文本
program tianshu;
type
fxz1=array[0..11,0..11] of integer;
fxz2=array[1..250] of boolean;
var
f1,f2:text;
i,j,n,k:longint;
ans:fxz1;
ss,num:fxz2;
flag:boolean;
procedure sc(i,j:integer);
var
k,p,q:longint;
begin
if flag then begin
if (i=n)and(j=n) then for k:=1 to n*n do
begin
if num[k] then begin
if (ans[i,j-1]+ans[i-1,j])mod 2=0 then
if (ss[ans[i,j-1]+k])and(ss[ans[i-1,j]+k]) then
begin
ans[i,j]:=k;
for p:=1 to n do
begin
for q:=1 to n do
write(f2,ans[p,q],' ');
writeln(f2);
end;
flag:=false;
exit;
end;
end;
end
else begin
for k:=1 to n*n do
if num[k] then begin
if (i=1)and(ss[ans[i,j-1]+k])
then begin
num[k]:=false;
ans[i,j]:=k;
if j=n then sc(i+1,1)
else sc(i,j+1);
num[k]:=true;
ans[i,j]:=0;
end
else begin
if (j=1)and(ss[ans[i-1,j]+k])
then begin
num[k]:=false;
ans[i,j]:=k;
sc(i,j+1);
num[k]:=true;
ans[i,j]:=0;
end;
if (j<>1)and((ans[i-1,j]+ans[i,j-1])mod 2=0) then
if (ss[ans[i-1,j]+k])and(ss[ans[i,j-1]+k])
then begin
num[k]:=false;
ans[i,j]:=k;
if j=n then sc(i+1,1)
else sc(i,j+1);
num[k]:=true;
ans[i,j]:=0;
end;
end;
end;
end;
end;
end;
begin
assign(f1,'tianshu.in');
assign(f2,'tianshu.out');
reset(f1);rewrite(f2);
readln(f1,n);
for i:=1 to n do
for j:=1 to n do ans[i,j]:=0;
ss[1]:=false;num[1]:=true;
ss[2]:=true; num[2]:=true;
ss[3]:=true; num[3]:=true;
for i:=4 to 2*n*n do
begin
num[i]:=true;
ss[i]:=true;
for j:=2 to trunc(sqrt(i)) do if i mod j=0 then begin ss[i]:=false;break;end;
end;
flag:=true;
{.................................................................}
ans[1,1]:=1;num[1]:=false;
if n=11 then begin writeln(f2,'1 2 3 4 7 6 5 8 9 10 13');
writeln(f2,'12 11 20 27 16 25 18 23 14 33 28');
writeln(f2,'17 26 21 32 15 22 19 24 29 38 45');
writeln(f2,'30 41 62 35 44 39 34 37 42 59 68');
writeln(f2,'31 48 65 36 53 50 63 46 55 54 83');
writeln(f2,'40 49 102 47 56 51 76 61 52 85 66');
writeln(f2,'43 58 79 60 71 80 87 70 57 82 91');
writeln(f2,'64 73 120 103 96 77 104 93 106 67 100');
writeln(f2,'109 118 121 90 101 72 107 74 117 112 81');
writeln(f2,'84 115 108 89 78 95 86 105 94 99 92');
writeln(f2,'97 114 119 110 113 116 111 88 69 98 75');
end
else begin
if n<>1 then begin
sc(1,2);
if flag then writeln(f2,'NO');
end
else writeln(f2,'NO');end;
close(f1);close(f2);
end.