比赛 NOIP2008集训模拟3 评测结果 AEWEEEEEEA
题目名称 移动骷髅 最终得分 20
用户昵称 name:弓虽 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-12 11:29:37
显示代码纯文本
program klgame(input,output);
 type
  sz=array [0..6,0..6] of '0'..'2';
var
 i,j,k:longint;
 n:longint;
 map:sz;

procedure find(map:sz);
var
 line:array [1..1000] of sz;
 step:array [1..1000] of longint;
 head,tail:longint;
 i,j,k:longint;
 f:boolean;
begin
 head:=0;
 tail:=1;
 line[1]:=map;
 f:=false;
  while (head<tail) and (not(f))
   do begin
    inc(head);
     for i:=1 to 5 do
      for j:= 1 to 5 do
       begin
        if line[head,i,j]<>'0' then begin
for k:=i-2 downto 1 do
          if line[head,k,j]<>'0' then begin
           inc(tail);
          line[tail]:=line[head];
          line[tail,k+1,j]:=line[head,i,j];
          line[tail,i,j]:='0';
           step[tail]:=step[head]+1;
            if line [tail,3,3]='2' then
             begin
              f:=true;
              writeln(step[tail]);
              break;
             end;
             end;
for k:=i+2 to 5 do
          if line[head,k,j]<>'0' then begin
           inc(tail);
          line[tail]:=line[head];
          line[tail,k-1,j]:=line[head,i,j];
          line[tail,i,j]:='0';
           step[tail]:=step[head]+1;
            if line [tail,3,3]='2' then
             begin
              f:=true;
              writeln(step[tail]);
              break;
             end;
             end;
for k:=j-2 downto 1 do
          if line[head,i,k]<>'0' then begin
           inc(tail);
          line[tail]:=line[head];
          line[tail,i,k+1]:=line[head,i,j];
          line[tail,i,j]:='0';
           step[tail]:=step[head]+1;
            if line [tail,3,3]='2' then
             begin
              f:=true;
              writeln(step[tail]);
              break;
             end;
             end;
for k:=j+2 to 5 do
          if line[head,i,k]<>'0' then begin
           inc(tail);
          line[tail]:=line[head];
          line[tail,i,k-1]:=line[head,i,j];
          line[tail,i,j]:='0';
           step[tail]:=step[head]+1;
            if line [tail,3,3]='2' then
             begin
              f:=true;
              writeln(step[tail]);
              break;
             end;
             end;
          end;
          if (f) then break;
          end;
          if (f) 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(map[j,k]);
      readln;
    end;
    writeln('level ',i,':');
    if map[3,3]='2' then writeln('0')
    else find(map);
    readln;
  end;
  close(input);
  close(output);
end.