比赛 |
NOIP2008集训模拟3 |
评测结果 |
AEWEEEEEEA |
题目名称 |
移动骷髅 |
最终得分 |
20 |
用户昵称 |
Achilles |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-12 09:45:06 |
显示代码纯文本
program klgame;
type
t=array[1..5,1..5]of '0'..'2';
var
table:t;
i,j,k,n:integer;
procedure find(table:t);
var
d:array[1..100]of t;
step:array[1..1000]of integer;
p1,p2,i,j,k,p:integer;
begin
d[1]:=table;
p1:=0;
p2:=1;
p:=0;
step[1]:=0;
while (p1<p2)and(p=0) do
begin
p1:=p1+1;
for i:=1 to 5 do
for j:=1 to 5 do
begin
if d[p1,i,j]<>'0' then begin
for k:=i-2 downto 1 do
if d[p1,k,j]<>'0' then begin
p2:=p2+1;
d[p2]:=d[p1];
d[p2,k+1,j]:=d[p1,i,j];
d[p2,i,j]:='0';
step[p2]:=step[p1]+1;
if d[p2,3,3]='2' then begin
writeln(step[p2]);
p:=1;
break;
end;
end;
for k:=i+2 to 5 do
if d[p1,k,j]<>'0' then begin
p2:=p2+1;
d[p2]:=d[p1];
d[p2,k-1,j]:=d[p1,i,j];
d[p2,i,j]:='0';
step[p2]:=step[p1]+1;
if d[p2,3,3]='2' then begin
writeln(step[p2]);
p:=1;
break;
end;
end;
for k:=j-2 downto 1 do
if d[p1,i,k]<>'0' then begin
p2:=p2+1;
d[p2]:=d[p1];
d[p2,i,k+1]:=d[p1,i,j];
d[p2,i,j]:='0';
step[p2]:=step[p1]+1;
if d[p2,3,3]='2' then begin
writeln(step[p2]);
p:=1;
break;
end;
end;
for k:=j+2 to 5 do
if d[p1,i,k]<>'0' then begin
p2:=p2+1;
d[p2]:=d[p1];
d[p2,i,k-1]:=d[p1,i,j];
d[p2,i,j]:='0';
step[p2]:=step[p1]+1;
if d[p2,3,3]='2' then begin
writeln(step[p2]);
p:=1;
break;
end;
end;
end;
if p=1 then break;
end;
if p=1 then break;
end;
end;
begin
assign(input,'klgame.in');
assign(output,'klgame.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
begin
for j:=1 to 5 do
begin
for k:=1 to 5 do
read(table[j,k]);
readln;
end;
writeln('level ',i,':');
if table[3,3]='2' then writeln(0) else find(table);
readln;
end;
close(input);
close(output);
end.