比赛 |
NOIP_3 |
评测结果 |
ATAAATAAAA |
题目名称 |
填数 |
最终得分 |
80 |
用户昵称 |
francis |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-12 22:10:35 |
显示代码纯文本
program tianshu;
const
fin='tianshu.in';
fou='tianshu.out';
var
a:array[1..11,1..11]of longint;
num:array[1..200,1..200]of longint;
l:array[1..200]of longint;
b:array[1..300]of boolean;
x,y,n,i,j:longint;
f1,f2:text;
procedure init;
begin
assign(f1,fin); assign(f2,fou);
reset(f1); rewrite(f2);
read(f1,n);
for i:=2 to n*n*2 do
begin
b[i]:=true;
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then b[i]:=false;
if b[i]=true then
begin
for j:=1 to n*n do
if (i>j)and(i-j<=n*n) then begin inc(l[j]); num[j,l[j]]:=i-j; end;
end;
end;
end;
procedure print;
var
i,j:longint;
begin
for i:=1 to n do
begin
for j:=1 to (n-1) do
write(f2,a[i,j],' ');
writeln(f2,a[i,n]);
end;
close(f1); close(f2); halt;
end;
procedure search(i,j:longint);
var
temp,ll,ii,jj,k:longint;
c:array[1..210]of integer;
begin
temp:=0;
for k:=1 to n*n do c[k]:=0;
jj:=j-1; ii:=i;
if jj>0 then
begin
for k:=1 to l[a[ii,jj]] do inc(c[num[a[ii,jj],k]]);
inc(temp);
end;
jj:=j; ii:=i-1;
if ii>0 then
begin
for k:=1 to l[a[ii,jj]] do inc(c[num[a[ii,jj],k]]);
inc(temp);
end;
for k:=1 to n*n do
if (c[k]=temp)and(b[k]=false) then
begin
a[i,j]:=k; b[k]:=true;
if (i=n)and(j=n) then print;
if j<n then search(i,j+1);
if (j=n)and(i<n) then search(i+1,1);
b[k]:=false;
end;
end;
begin
init;
a[1,1]:=1;
b[1]:=true;
for i:=2 to 110 do b[i]:=false;
search(1,2);
write(f2,'NO');
close(f1); close(f2);
end.