- 27
- 0
- 约1.82万字
- 约 42页
- 2017-07-03 发布于浙江
- 举报
广度宽度优先搜索l
【深搜参考程序】 program EX8_4_1; const maxn=50; var map:array [1..maxn,1..maxn] of integer; f:boolean; n,m,i,j,desx,desy,soux,souy,totstep:integer; route:array[1..maxn] of record x,y : integer; end; procedure move(x,y,step:integer); begin map[x,y]:=step; //走一步,作标记,把步数记下来 route[step].x := x; route[step].y:= y; //记路径 if (x=desx) and (y=desy) then begin f:=true; totstep:=step; end else begin if (ym) and (map[x,y+1]=0) then move (x,y+1,step+1); //向右 if not f and (xn)and(map[x+1,y]=0) then move(x+1,y ,step+1); //往下 if not f and (y1)and(map[x,y-1]=0) then move(x,y-1, step+1); //往左 if not f and (x1)and(map[x-1,y]=0) then move(x-1,y, step+1); //往上 end; end; BEGIN readln(n,m); //n行m列的迷宫 for i:=1 to n do //读入迷宫,0表示通,-1表示不通 begin for j:=1 to m do read(map[i,j]); readln; end; write(input the enter:); readln(soux,souy); //入口 write(input the exit:); readln(desx,desy); //出口 f:=false; //f=false表示无解;f=true表示找到了一个解 move(soux,souy,1); if f then for i:=1 to totstep do //输出直迷宫的路径 write(route[i]:4); else writeln (no way.); END. 【广搜参考程序】 program EX8_4_2; const maxn=50; u:array[1..4] of integer=(0,1,0,-1); w:array[1..4] of integer=(1,0,-1,0); var map:array [1..maxn,1..maxn] of integer; f:boolean; n,m,i,j,desx,desy,soux,souy,head,tail,x,y:integer; route:array[1..maxn] of record x,y,pre : integer; end; procedure print(d:integer); begin if route[d].pre0 then print(route[d].pre); write((,route[d].x,,,route[d].y,)); end; BEGIN readln(n
您可能关注的文档
最近下载
- 2025年江门市直遴选笔试真题汇编带答案解析.docx VIP
- 6.1《大堰河—我的保姆》《再别康桥》比较阅读+课件++2023-2024学年统编版高中语文选择性必修下册.pptx
- 中国急性胰腺炎诊治指南(2021).pdf VIP
- 气温对畜禽的影响56课件.pptx VIP
- [qc成果]地下室底板自粘型防水卷材预铺反粘式防水施工质量控制.doc
- 高血压危象的诊治ppt课件.pptx VIP
- 第三节湖南省基本概况与主要文旅资源.pptx VIP
- JGT223-2017 聚羧酸系高性能减水剂.docx
- 2025年江门市直遴选笔试真题汇编带答案解析.docx VIP
- 工程伦理-第2章工程中风险、安全与责任.pptx VIP
原创力文档

文档评论(0)