迷宫

program migong;
type node=record
          xx,yy:longint;
     end;
     all=array[1..10,1..10]of longint;
 const n=400;
 dx:array[1..4]of longint=(0,1,0,-1);
 dy:array[1..4]of longint=(1,0,-1,0);
 a:all=((0,0,0,0,0,0,1,0,1,1),
        (0,1,0,1,1,0,0,0,0,0),
        (0,1,0,1,1,0,1,1,1,0),
        (0,1,0,0,0,0,0,1,0,0),
        (0,1,1,1,1,1,1,1,1,1),
        (0,0,0,1,0,1,0,0,0,0),
        (0,1,1,1,0,0,0,1,1,1),
        (0,0,0,0,0,1,0,0,0,0),
        (1,1,0,1,1,1,0,1,1,0),
        (1,1,1,1,1,1,0,1,1,1));
 var head,tail,k,x1,y1,x2,y2,nx,ny:longint;
     state:array[1..n]of node;
     father:array[1..n]of longint;
 function check:boolean;
 begin
  check:=false;
  nx:=state[head].xx+dx[k];ny:=state[head].yy+dy[k];
  if (nx<1)or(nx>10)or(ny<1)or(ny>10) then
     check:=false
      else if a[ny,nx]=1 then check:=false
       else check:=true;
 end;
 function dupe:boolean;
 var i,j:longint;buf:boolean;
 begin
  buf:=false;i:=0;
  repeat
   inc(i);
   if (state[i].xx=state[tail].xx)and(state[i].yy=state[tail].yy)then
   buf:=true else buf:=false
    until buf or(i>=tail-1);
   dupe:=buf;
   end;
   procedure print;
   var buf:array[1..n]of longint;
   i,j,m:longint;
   begin
    m:=1;j:=tail;buf[1]:=j;
    while j>0 do
     begin
      j:=father[j];
      inc(m);buf[m]:=j;
     end;
    for i:=m-1 downto 2 do
      write('(',state[buf[i]].xx,',',state[buf[i]].yy,')','--');
      writeln('(',state[buf[1]].xx,',',state[buf[1]].yy,')');
    halt;
 end;
begin
 x1:=8;y1:=1;x2:=7;y2:=10;
 state[1].xx:=x1;
 state[1].yy:=y1;
 head:=1;tail:=1;father[head]:=0;
 repeat
  for k:=1 to 4 do
   if check then
    begin
     inc(tail);
     father[tail]:=head;
     state[tail].xx:=nx;
     state[tail].yy:=ny;
     if dupe then dec(tail)
      else if (state[tail].xx=x2)and(state[tail].yy=y2)
           then print;
   end;
 head:=head+1;
 until head>tail;
end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值