比赛 |
NOIP2008集训模拟3 |
评测结果 |
AAAAAATAAA |
题目名称 |
移动骷髅 |
最终得分 |
90 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 11:26:23 |
显示代码纯文本
program klgame;
const
d:array[1..4,1..2] of integer=((1,0),(-1,0),(0,1),(0,-1));
maxn=100000;
type
atype=array[0..6,0..6] of integer;
var
q:array[1..maxn] of atype;
head,tail,len,k,x,y,tm:longint;
p,qs:atype;
n,i:longint;
dep:array[1..maxn] of longint;
a:atype;
procedure init;
var
i,j:integer;
ch:char;
begin
for i:=1 to 5 do
begin
for j:=1 to 5 do
begin
read(ch);
a[i,j]:=ord(ch)-48
end;
readln;
end;
readln;
end;
function find(a:atype):boolean;
var
i,j,k:integer;
ok:boolean;
begin
for i:=1 to tail do
begin
ok:=true;
for j:=1 to 5 do
begin
for k:=1 to 5 do
if a[j,k]<>q[i][j,k]
then begin
ok:=false;
break
end;
if not ok then break;
end;
if ok then exit(true);
end;
exit(false);
end;
procedure print;
begin
writeln('level ',i,':');
writeln(dep[tail]);
end;
procedure main;
var
i,j,dd:integer;
begin
head:=1; tail:=1; q[1]:=a;
dep[1]:=0;
len:=1;
repeat
p:=q[head];
for i:=1 to 5 do
for j:=1 to 5 do
if (p[i,j]=1) or (p[i,j]=2)
then begin
k:=p[i,j];
for dd:=1 to 4 do
begin
x:=i; y:=j;
while (x>=1) and (x<=5) and (y>=1) and (y<=5) do
begin
if (p[x+d[dd,1],y+d[dd,2]]=1) or (p[x+d[dd,1],y+d[dd,2]]=2)
then break;
x:=x+d[dd,1]; y:=y+d[dd,2];
end;
if (x>=1) and (x<=5) and (y>=1) and (y<=5)
then begin
qs:=p; qs[i,j]:=0; qs[x,y]:=p[i,j];
if not find(qs)
then begin
tail:=tail+1;
q[tail]:=qs;
dep[tail]:=dep[head]+1;
inc(len);
if qs[3,3]=2 then begin print; exit end;
end;
end;
end;
end;
head:=head+1; dec(len);
until len=0;
end;
begin
assign(input,'klgame.in');
assign(output,'klgame.out');
reset(input); rewrite(output);
readln(n);
for i:=1 to n do
begin
init;
main;
end;
close(input); close(output);
end.