记录编号 8044 评测结果 AAAAAAAAAA
题目名称 移动骷髅 最终得分 100
用户昵称 Gravatarthegy 是否通过 通过
代码语言 Pascal 运行时间 0.709 s
提交时间 2008-11-12 19:01:04 内存使用 4.00 MiB
显示代码纯文本
//na                            :cuixiaofei;
//da                            :08_11_12;
program klgame;
  type
    sss                         =record
                                b:array[0..6,0..6] of longint;
                                ge:longint;
                                ji:array[1..25,1..2] of longint;
                                f:longint;
                                hanshu:longint;
                                end;
  var
    n,kk                        :longint;
    a                           :array[1..10000] of sss;
    f1,f2                       :text;
  procedure jinru(k:longint);
    var
      i,ge                      :longint;
  begin
    ge:=0;
    i:=a[k].f;
    while i>0 do
      begin
        i:=a[i].f;
        inc(ge);
      end;
      writeln(f2,'level ',kk,':');
    writeln(f2,ge);
  end;
  function pan(k:longint):longint;
  begin
    pan:=0;
    if (a[k].b[3,3]=2) then
      begin
        jinru(k);
        pan:=1;
      end;
  end;

  procedure swap(var x,y:longint);
    var
      t                           :longint;
  begin
    t:=x;
    x:=y;
    y:=t;
  end;

  function pp(x,y:longint):longint;
    var
      i,j                       :longint;
  begin
    pp:=1;
    for i:=1 to 5 do
      for j:=1 to 5 do
        if a[x].b[i,j]<>a[y].b[i,j] then
          begin
            pp:=0;
           exit;
         end;
  end;
  function zhuan(k:longint):longint;
    var
      i,j,ge                    :longint;
      ji                        :longint;
  begin
    ji:=0;
    ge:=0;
    for i:=1 to 5 do
      for j:=1 to 5 do
        begin
          ji:=ji+a[k].b[i,j] shl ge;
          inc(ge);
        end;
    zhuan:=ji;
  end;

  function chong(k:longint):longint;
    var
      i                         :longint;
  begin
    chong:=0;
//    if panchong[zhuan(k)]=false then
    for i:=1 to k-1 do
      if a[i].hanshu=a[k].hanshu then
      chong:=1;
  end;

  procedure chaozuo;
    var
      tou,wei,i,j,k,x,y         :longint;
  begin
    tou:=1;
    wei:=1;
    if pan(tou)=1 then
      exit;
//    panchong[zhuan(tou)]:=false;
    a[tou].hanshu:=zhuan(tou);
    while tou<=wei do
      begin
        for k:=1 to a[tou].ge do
          begin
            x:=a[tou].ji[k,1];
            y:=a[tou].ji[k,2];
            for i:=1 to 4 do
              begin
                case i of
                  1  :  begin
                          for j:=x+1 to 5 do
                            if a[tou].b[j,y]<>0 then
                              begin
                                inc(wei);
                                a[wei]:=a[tou];
                                a[wei].f:=tou;
                                swap(a[wei].b[j-1,y],a[wei].b[x,y]);
                                a[wei].ji[k,1]:=j-1;
                                if pan(wei)=1 then
                                  exit;
                                a[wei].hanshu:=zhuan(wei);
                                if chong(wei)=1 then
                                  dec(wei);
                                break;
                              end;
                         end;
                  2  :  begin
                          for j:=x-1 downto 1 do
                            if a[tou].b[j,y]<>0 then
                              begin
                                inc(wei);
                                a[wei]:=a[tou];
                                a[wei].f:=tou;
                                swap(a[wei].b[j+1,y],a[wei].b[x,y]);
                                a[wei].ji[k,1]:=j+1;
                                if pan(wei)=1 then
                                  exit;
                                a[wei].hanshu:=zhuan(wei);
                                if chong(wei)=1 then
                                  dec(wei);
                                break;
                              end;
                        end;
                  3  :  begin
                          for j:=y-1 downto 1 do
                            if a[tou].b[x,j]<>0 then
                              begin
                                inc(wei);
                                a[wei]:=a[tou];
                                a[wei].f:=tou;
                                swap(a[wei].b[x,j+1],a[wei].b[x,y]);
                                a[wei].ji[k,2]:=j+1;
                                a[wei].hanshu:=zhuan(wei);
                                if pan(wei)=1 then
                                  exit;
                                if chong(wei)=1 then
                                  dec(wei);
                                break;
                              end;
                        end;
                  4  :  begin
                          for j:=y+1 to 5 do
                            if a[tou].b[x,j]<>0 then
                              begin
                                inc(wei);
                                a[wei]:=a[tou];
                                a[wei].f:=tou;
                                swap(a[wei].b[x,j-1],a[wei].b[x,y]);
                                a[wei].ji[k,2]:=j-1;
                                if pan(wei)=1 then
                                  exit;
                                a[wei].hanshu:=zhuan(wei);
                                if chong(wei)=1 then
                                  dec(wei);
                                break;
                              end;
                        end;
                   end;
              end;
          end;
        inc(tou);
      end;
  end;

  procedure init;
    var
      i,j,k                     :longint;
      c                         :char;
  begin
    assign(f1,'klgame.in');
    reset(f1);
    assign(f2,'klgame.out');
    rewrite(f2);
    readln(f1,n);
    for kk:=1 to n do
      begin
        fillchar(a,sizeof(a),0);
        for i:=1 to 5 do
          begin
          for j:=1 to 5 do
            begin
              read(f1,c);
              if c='0' then
                a[1].b[i,j]:=0
              else if c='1' then
                a[1].b[i,j]:=1
              else
                a[1].b[i,j]:=2;
              if a[1].b[i,j]<>0 then
                begin
                  inc(a[1].ge);
                  a[1].ji[a[1].ge,1]:=i;
                  a[1].ji[a[1].ge,2]:=j;
                end;
            end;
           readln(f1);
          end;
        chaozuo;
        readln(f1);
      end;
    close(f1);
    close(f2);
  end;

  begin
    init;
  end.