比赛 NOIP_3 评测结果 RRRRRRRRRR
题目名称 填数 最终得分 0
用户昵称 bing 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-19 10:37:51
显示代码纯文本
program bing;
const
 sushu:array[1..26] of integer=(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101);
type
 arr=array[1..100] of boolean;
 ar=array[1..10,1..10]of integer;
var
 a,at:ar;
 c:arr;
 n:integer;
 s:longint;
procedure init;
var
 i,j:Integer;
begin
 readln(n);
 fillchar(a,sizeof(a),0);
 a[1,1]:=1;
 s:=0;
 fillchar(c,sizeof(c),true);
end;
function pd(x:integer):boolean;
var i:integer;
begin
 pd:=false;
 for i:=1 to 26 do
 if (x=sushu[i])then begin
  pd:=true;exit;end;
end;
procedure nb(x,y:integer;a:ar;c:arr);
var
 i,j:Integer;t1:ar;t2:arr;
begin
 t1:=a;t2:=c;
 for i:=2 to n*n do
 if t2[i]=true then
 if ((x=1)and pd(i+t1[x,y-1]))or((y=1)and pd(i+t1[x-1,y]))
 or((x<>1)and(y<>1)and pd(i+t1[x-1,y]) and pd(i+t1[x,y-1]))
 then
 begin
 t1[x,y]:=i;inc(y);t2[i]:=false;
 if y>n then begin inc(x);y:=1;end;
 if x>n then
  begin
   inc(s);
   if s=1 then at:=t1;
  end
 else nb(x,y,t1,t2);
 end;
end;
procedure put(a:ar);
var
 i,j:integer;
begin
 for i:=1 to n do
 begin
 for j:=1 to n do
 write(a[i,j],' ');
 writeln;
 end;
end;
begin
 init;
 nb(1,2,a,c);
 put(at);
end.