⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maze.pas

📁 PASCAL光盘资料PASCAL光盘资料PASCAL光盘资料
💻 PAS
字号:
program E1_5; {Maze: search path from the labyrinth}
const maxn=12;
type arr=array[1..maxn,1..maxn] of 0..1;
var a,b:arr;
    bx,by,ex,ey,i,j,m,n:integer;
    p:string;
    f:boolean;
    input,output:text;

procedure search(x,y:integer;b:arr;p:string);
var i,j,k,x1,y1:integer;
    b1:arr;
    p1:string;
begin
 for i:=1 to 4 do
  begin
   for j:=1 to m do for k:=1 to n do b1[j,k]:=b[j,k];
   p1:=p;x1:=x;y1:=y;
   case i  of
        1:if (y>1) and (a[x,y-1]=1) and (b[x,y-1]=0) then y1:=y-1;
        2:if (x>1) and (a[x-1,y]=1) and (b[x-1,y]=0) then x1:=x-1;
        3:if (y<n) and (a[x,y+1]=1) and (b[x,y+1]=0) then y1:=y+1;
        4:if (x<m) and (a[x+1,y]=1) and (b[x+1,y]=0) then x1:=x+1;
   end;
   if (x1<>x) or (y1<>y) then
    begin
    b1[x1,y1]:=1;
     p1:=p1+'->('+chr(ord('0')+x1)+','+chr(ord('0')+y1)+')';
     if  (x1=ex) and (y1=ey) then begin
                                   writeln(output,p1);
                                   f:=true;
                                   end
                               else search(x1,y1,b1,p1);
    end;
  end;
end;

begin  {main}
 assign(input,'maze.in');
 reset(input);
 readln(input,m,n);
 for i:=1 to m do
  for j:=1 to n do read(input,a[i,j]);
 for i:=1 to m do
  for j:=1 to n do b[i,j]:=0;
 readln(input,bx,by);
 readln(input,ex,ey);
 close(input);
 b[bx,by]:=1;
 p:='('+chr(ord('0')+bx)+','+chr(ord('0')+by)+')';
 f:=false;
 assign(output,'maze.out');
 rewrite(output);
 search(bx,by,b,p);
 if not f then writeln(output,-1);
 close(output)
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -