记录编号 8128 评测结果 AAAAAAAAAA
题目名称 移动骷髅 最终得分 100
用户昵称 Gravatarelysian 是否通过 通过
代码语言 Pascal 运行时间 1.112 s
提交时间 2008-11-13 08:05:10 内存使用 2.98 MiB
显示代码纯文本
program elysian;
const
dx:array[1..4] of integer=(1,-1,0,0);
dy:array[1..4] of integer=(0,0,1,-1);
fin='klgame.in';fout='klgame.out';
type
arr=array[1..5] of string[5];
var
f1,f2:text;
i,j,kk,n,t1,t2,p,t:longint;
a:array[1..100000] of arr;
tmp:arr;
chong:boolean;
ch:char;

procedure print;
begin
writeln(f2,'level ',kk,':');
writeln(f2,t);
end;

procedure re(head,tail:longint);
var
i,j,k:longint;
flag:boolean;
begin
for i:=1 to tail-1 do
begin
flag:=false;
  for k:=1 to 5 do
     if a[tail,k]<>a[i,k] then begin flag:=true;break;end;
if flag=false  then begin chong:=true;exit;end;
end;

end;


procedure bfs;
var
ff,failf:boolean;
head,tail,i,k,x1,y1,tx,ty,fst,lst,v,xx,yy:longint;
begin
head:=1;tail:=1;p:=t+1;t:=0;
repeat
inc(t);
fst:=head;
lst:=tail;

for v:=fst to lst do
for xx:=1 to 5 do
for yy:=1 to 5 do
if a[v,xx,yy]<>'0' then
for k:=1 to 4 do
 begin
 x1:=xx+dx[k];
 y1:=yy+dy[k];
 tx:=x1;ty:=y1;
 if (x1>0)and(x1<=5)and(y1>0)and(y1<=5) then
  if a[v,x1,y1]='0' then
  begin
      failf:=false;ff:=false;
      repeat
       if (tx>5)or(tx<1)or(ty>5)or(ty<1) then begin failf:=true;break;end;
       tx:=tx+dx[k];
       ty:=ty+dy[k];
       if (tx<=5)and(tx>0)and(ty<=5)and(ty>0) then
         if a[v,tx,ty]<>'0' then ff:=true;
      until (ff=true)or(failf=true);
     if failf=false then
      begin
        tx:=tx-dx[k];ty:=ty-dy[k];
        if (tx=3)and(ty=3)and(a[v,xx,yy]='2') then  begin print;exit;end;
          inc(tail);
          a[tail]:=a[v];
          a[tail,tx,ty]:=a[v,xx,yy];
          a[tail,xx,yy]:='0';
          chong:=false;
          re(head,tail);
          if chong=true then begin a[tail]:=tmp;dec(tail);end;
      end;
   end;

end; //end for

head:=lst+1;

until head>=tail;

end;


begin
assign(f1,fin);reset(f1);
assign(f2,fout);rewrite(f2);
i:=0;
readln(f1,n);
kk:=0;
repeat
inc(kk);
t1:=0;
for i:=1 to 5 do
begin
readln(f1,a[1,i]);
end;
bfs;
readln(f1);
until kk>=n;
close(f1);
close(f2);
end.