比赛 |
NOIP_3 |
评测结果 |
ATAAAAAAAA |
题目名称 |
填数 |
最终得分 |
90 |
用户昵称 |
NOIer |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-12 21:17:01 |
显示代码纯文本
//Problem : Tianshu;
//Author : CaiXinXiao;
//Way : Search;
Program TSearch;
Const
MaxN = 100;
Inf = 'tianshu.in';
Ouf = 'tianshu.out';
Var
Data : Array[1..MaxN,1..MaxN] of Longint;
Flag : Array[1..MaxN*MaxN] of Boolean;
Ss : Array[1..MaxN*MaxN] of Boolean;
N : Longint;
Function PD(x,y,k:Longint):Boolean;
Begin
PD:=true;
if x > 1 then if Not(Ss[Data[ x - 1 , y ] + k ]) then PD := False;
if y > 1 then if Not(Ss[Data[ x , y - 1 ] + k ]) then PD := False;
End;
Procedure SuShu;
Var
r,k:Longint;
Begin
For r:=1 to 2*n*n do Ss[r]:=true;
For r:=2 to n*3 div 2 do
Begin
k:=r*2;
While k<=2*n*n do
Begin
Ss[k]:=false;
k:=k+r
End;
End;
End;
Procedure Init;
Var
R:Longint;
Begin
assign(input,Inf); reset(input);
assign(output,Ouf); rewrite(output);
Readln(n);
if N=1 then
Begin
writeln('NO');
Close(input);
Close(output);
Halt;
End;
SuShu;
Data[1,1]:=1;
For r:=1 to N*N do Flag[r]:=false;
Flag[1]:=True;
End;
Procedure Print;
Var
r:Longint;
k:Longint;
Begin
For r:=1 to n do
Begin
For k:=1 to n do
Begin
Write(Data[r,k]);
if k<>n then Write(' ');
End;
Writeln;
End;
close(input);
close(output);
Halt;
End;
Procedure Search(x,y,dep:Longint);
Var
r:Longint;
Begin
if Dep=n*n then Print
Else
For r:=1 to n*n do
if not(Flag[r]) and PD(x,y,r) then
Begin
Data[x,y]:=r;
Flag[r]:=true;
if y=n then Search(x+1,1,dep+1)
Else
Search(x,y+1,dep+1);
Flag[r]:=false
End;
End;
BEGIN
Init;
Search(1,2,1);
Writeln('NO');
close(input);
close(output);
END.