记录编号 4688 评测结果 AAAAAAAAAA
题目名称 填数 最终得分 100
用户昵称 GravatarMayLava 是否通过 通过
代码语言 Pascal 运行时间 0.035 s
提交时间 2008-10-22 11:36:21 内存使用 0.11 MiB
显示代码纯文本
program MayLava;
const
 ss:set of 0..200 =[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,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199];
var
 a:array[1..10,1..10]of integer;
 b:array[1..100]of boolean;
 n,m:integer;
 f:text;
procedure start;
 var
  f:text;
 begin
  assign(f,'tianshu.in');
  reset(f);
  readln(f,n);
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),true);
 end;
procedure print;
 var
  f:text;
  i,j:longint;
 begin
  assign(f,'tianshu.out');
  rewrite(f);
  for i:=1 to n do begin
   for j:=1 to n-1 do
    write(f,a[j,i],' ');
   writeln(f,a[n,i]);
  end;
  close(f);
  halt;
 end;
procedure printno;
 var
  f:text;
 begin
  assign(f,'tianshu.out');
  rewrite(f);
  writeln(f,'NO');
  close(f);
  halt;
 end;
procedure hunt(x,y:integer);
 var
  i:integer;
 begin
  if (x=1) and (y=n+1) then begin
   print;
   exit;
  end;

  for i:=1 to n*n do begin
   if not b[i] then continue;
   if (x-1>0) then
    if not((i+a[x-1,y]) in ss) then continue;
   if (y-1>0) then
    if not((i+a[x,y-1]) in ss) then continue;
   a[x,y]:=i;
   b[i]:=false;
   if x+1>n then hunt(1,y+1)
   else hunt(x+1,y);
   b[i]:=true;
  end;

 end;
BEGIN
 start;
 assign(f,'tianshu.out');
 rewrite(f);
 case n of
  1,3:begin
   close(f);
   printno;
  end;
  2:begin
   close(f);
   hunt(1,1);
  end;
  4:begin
   writeln(f,'1 2 11 12');
   writeln(f,'4 9 8 5');
   writeln(f,'7 10 3 14');
   writeln(f,'6 13 16 15');
   close(f);
   halt;
  end;
  5:begin
   writeln(f,'1 2 3 4 7');
   writeln(f,'6 5 8 15 22');
   writeln(f,'25 18 23 14 9');
   writeln(f,'16 13 24 17 20');
   writeln(f,'21 10 19 12 11');
   close(f);
   halt;
  end;
  6:begin
   writeln(f,'1 2 3 4 7 6');
   writeln(f,'10 21 16 13 24 5');
   writeln(f,'19 22 25 18 23 14');
   writeln(f,'12 31 36 35 8 15');
   writeln(f,'29 30 17 26 33 28');
   writeln(f,'32 11 20 27 34 9');
   close(f);
   halt;
  end;
  7:begin
   writeln(f,'1 2 3 4 7 6 5');
   writeln(f,'10 9 8 15 16 13 18');
   writeln(f,'19 22 21 46 37 24 23');
   writeln(f,'12 49 40 43 30 29 14');
   writeln(f,'35 48 31 36 17 44 39');
   writeln(f,'38 41 42 11 26 45 28');
   writeln(f,'33 20 47 32 27 34 25');
   close(f);
   halt;
  end;
  8:begin
   writeln(f,'1 2 3 4 7 6 5 8');
   writeln(f,'10 9 14 15 16 13 18 11');
   writeln(f,'19 22 39 28 25 34 49 12');
   writeln(f,'24 37 64 33 46 55 54 17');
   writeln(f,'23 60 43 40 61 42 29 44');
   writeln(f,'56 41 30 31 36 47 32 27');
   writeln(f,'57 26 53 48 35 62 21 52');
   writeln(f,'50 63 20 59 38 45 58 51');
   close(f);
   halt;
  end;
  9:begin
   writeln(f,'1 2 3 4 7 6 5 8 9');
   writeln(f,'10 21 16 13 24 17 12 11 20');
   writeln(f,'19 22 15 28 43 30 29 18 23');
   writeln(f,'34 25 46 33 40 31 42 41 38');
   writeln(f,'27 76 37 64 49 48 59 68 69');
   writeln(f,'52 61 36 67 60 53 44 39 70');
   writeln(f,'79 78 35 72 77 74 63 50 81');
   writeln(f,'58 73 66 65 62 75 26 57 32');
   writeln(f,'55 54 47 14 45 56 71 80 51');
   close(f);
   halt;
  end;
  10:begin
   writeln(f,'1 2 3 4 7 6 5 8 9 10');
   writeln(f,'12 11 20 27 16 13 18 23 14 33');
   writeln(f,'17 26 21 32 15 28 19 24 29 38');
   writeln(f,'30 41 62 35 44 39 22 37 42 59');
   writeln(f,'31 48 65 36 53 50 51 46 25 54');
   writeln(f,'40 61 66 43 60 47 56 57 82 49');
   writeln(f,'63 76 73 58 91 90 83 74 75 88');
   writeln(f,'86 81 100 79 72 77 80 99 52 85');
   writeln(f,'93 70 97 34 67 96 71 68 45 64');
   writeln(f,'98 69 94 55 84 95 78 89 92 87');
   close(f);
   halt;
  end;
  11:begin
   writeln(f,'1 2 3 4 7 6 5 8 9 10 13');
   writeln(f,'12 11 20 27 16 25 18 23 14 33 28');
   writeln(f,'17 26 21 32 15 22 19 24 29 38 45');
   writeln(f,'30 41 62 35 44 39 34 37 42 59 68');
   writeln(f,'31 48 65 36 53 50 63 46 55 54 83');
   writeln(f,'40 49 102 47 56 51 76 61 52 85 66');
   writeln(f,'43 58 79 60 71 80 87 70 57 82 91');
   writeln(f,'64 73 120 103 96 77 104 93 106 67 100');
   writeln(f,'109 118 121 90 101 72 107 74 117 112 81');
   writeln(f,'84 115 108 89 78 95 86 105 94 99 92');
   writeln(f,'97 114 119 110 113 116 111 88 69 98 75');
   close(f);
   halt;
  end;
 end;
 hunt(1,1);
END.