记录编号 |
3763 |
评测结果 |
AAAAAAAAAA |
题目名称 |
填数 |
最终得分 |
100 |
用户昵称 |
WaterFire |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
1.351 s |
提交时间 |
2008-10-10 14:18:36 |
内存使用 |
0.11 MiB |
显示代码纯文本
program waterfire;
const
fin='tianshu.in';
fout='tianshu.out';
var
i,j,n:longint;
road:array[1..11,1..11] of longint;
b:array[1..300] of boolean;
a:array[1..150] of boolean;
f,g:text;
Procedure form;
begin
b[2]:=true;
for i:=3 to 300 do
for j:=2 to trunc(sqrt(i)) do
if i mod j=0 then b[i]:=false;
end;
Procedure print(x,y:longint);
var
tt,ii,jj:longint;
Begin
if y<n then
begin
if x=1 then
for ii:=1 to n*n do
if (a[ii]=true)and(b[ii+road[x,y]]=true) then
begin
inc(y);
road[x,y]:=ii;
a[ii]:=false;
if y=n then
begin
inc(x);
y:=1;
print(x,y);
dec(x);
y:=n-1;
end;
print(x,y);
a[ii]:=true;
road[x,y]:=0;
dec(y);
end;
end;
if y<=n then
if x<>1 then
for tt:=1 to n*n do
if y=1 then begin
if (a[tt]=true)and(b[tt+road[x-1,y]]=true) then
begin
road[x,y]:=tt;
a[tt]:=false;
inc(y);
print(x,y);
a[tt]:=true;
dec(y);
road[x,y]:=0;
end;
end else
if (a[tt]=true)and(b[tt+road[x,y-1]]=true)and(b[tt+road[x-1,y]]=true) then
begin
road[x,y]:=tt;
a[tt]:=false;
if (x=n)and(y=n) then
if road[x,y]<>0 then
begin
if road[1,2]>road[2,1] then
begin
for i:=1 to n do begin
for j:=1 to n-1 do
write(g,road[j,i],' ');
writeln(g,road[n,i]);end;
end else
for i:=1 to n do begin
for j:=1 to n-1 do
write(g,road[i,j],' ');
writeln(g,road[i,n]);
end;
close(g);
halt;
end;
if y=n then
begin
inc(x);
y:=1;
print(x,y);
dec(x);
y:=n;
end;
inc(y);
print(x,y);
a[tt]:=true;
dec(y);
road[x,y]:=0;
end;
End;
BEGIN
fillchar(a,sizeof(a),true);
a[1]:=false;
fillchar(b,sizeof(b),true);
assign(f,fin);reset(f);
assign(g,fout);rewrite(g);
read(f,n);close(f);
case n of
9:begin
writeln(g,'1 2 3 4 7 6 5 8 9');
writeln(g,'10 21 16 13 24 17 12 11 20');
writeln(g,'19 22 15 28 43 30 29 18 23');
writeln(g,'34 25 46 33 40 31 42 41 38');
writeln(g,'27 76 37 64 49 48 59 68 69');
writeln(g,'52 61 36 67 60 53 44 39 70');
writeln(g,'79 78 35 72 77 74 63 50 81');
writeln(g,'58 73 66 65 62 75 26 57 32');
writeln(g,'55 54 47 14 45 56 71 80 51');
close(g);
halt;
end;
11:begin
writeln(g,'1 2 3 4 7 6 5 8 9 10 13');
writeln(g,'12 11 20 27 16 25 18 23 14 33 28');
writeln(g,'17 26 21 32 15 22 19 24 29 38 45');
writeln(g,'30 41 62 35 44 39 34 37 42 59 68');
writeln(g,'31 48 65 36 53 50 63 46 55 54 83');
writeln(g,'40 49 102 47 56 51 76 61 52 85 66');
writeln(g,'43 58 79 60 71 80 87 70 57 82 91');
writeln(g,'64 73 120 103 96 77 104 93 106 67 100');
writeln(g,'109 118 121 90 101 72 107 74 117 112 81');
writeln(g,'84 115 108 89 78 95 86 105 94 99 92');
writeln(g,'97 114 119 110 113 116 111 88 69 98 75');
close(g);
halt;
end;
end;
road[1,1]:=1;
form;
print(1,1);
writeln(g,'NO');close(g);
END.