博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
遍历迷宫
阅读量:6603 次
发布时间:2019-06-24

本文共 1977 字,大约阅读时间需要 6 分钟。

 走迷宫

1 #include
2 #define MAXSIZE 15 3 char point[MAXSIZE][MAXSIZE]={ 4 {
'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X'}, 5 {
' ','o','o','o','o','o','X','o','o','X','o','o','o','o','X'}, 6 {
'X','o','X','o','X','X','X','X','o','X','X','X','X','X','X'}, 7 {
'X','o','X','o','o','o','o','X','o','o','X','X','X','X','X'}, 8 {
'X','o','X','o','o','X','o','X','X','o','X','o','o','o','X'}, 9 {
'X','o','X','o','o','X','o','X','o','o','X','o','X','o','X'},10 {
'X','o','o','X','o','o','o','X','o','X','X','o','X','o','X'},11 {
'X','X','o','o','X','X','X','X','o','X','X','o','X','o','o'},12 {
'X','o','o','o','X','o','X','X','o','o','o','o','X','X','o'},13 {
'X','o','X','o','o','o','X','X','X','X','X','o','X','o','o'},14 {
'X','o','o','o','X','o','X','X','o','o','o','o','X','o','X'},15 {
'X','X','o','o','X','o','X','X','o','X','X','X','X','o','X'},16 {
'X','o','X','X','X','o','X','X','o','X','X','o','o','o','X'},17 {
'X','o','o','o','X','o','o','o','o','X','X','o','X','o','X'},18 {
'X','X','X','o','o','o','X','X','o','o','o','o','X','o','e'}19 };20 bool visited[MAXSIZE][MAXSIZE];21 bool flag = false; //标记是否已经找到了出口 22 23 //遍历迷宫 24 void pathFind(char (*point)[MAXSIZE],int x,int y){25 if(!visited[x][y]){26 visited[x][y]=true;27 if(point[x][y]=='e'){28 point[x][y]=' ';29 flag=true;30 return ;31 }32 point[x][y]=' ';33 }34 if((point[x+1][y]=='o'||point[x+1][y]=='e')&&visited[x+1][y]!=true&&(x+1
=0)) {
//向负x轴 40 pathFind(point,x,y-1);41 if(flag)42 return ;43 }44 if((point[x-1][y]=='o'||point[x-1][y]=='e')&&visited[x-1][y]!=true&&(x-1>=0)) {
//向正y轴 45 pathFind(point,x-1,y);46 if(flag)47 return ;48 }49 if((point[x][y+1]=='o'||point[x][y+1]=='e')&&visited[x][y+1]!=true&&(y+1

 

转载于:https://www.cnblogs.com/hoojjack/p/4764845.html

你可能感兴趣的文章
PHP中htmlentities和htmlspecialchars的区别
查看>>
Best Part
查看>>
ClassPathXMLApplicationContext上下文加载过程
查看>>
JS模拟select下拉菜单
查看>>
线性方程组迭代求解——Jacobi迭代算法(Python实现)
查看>>
vmware workstation14永久激活密钥分享
查看>>
HDU 3954 Level up(多颗线段树+lazy操作)
查看>>
hdu Stars(树状数组)
查看>>
jquery中ajax方法load get post与脚本文件如php脚本连接时,脚本怎样接受数据?
查看>>
PHP面向对象的进阶学习(抽像类、接口、final、类常量)
查看>>
三种数据库访问——Spring3.2 + Hibernate4.2
查看>>
datasg中的数据的存储结
查看>>
iOS 多线程 之 GCD(大中枢派发)(一)
查看>>
[记]SAF 中缓存服务的实现
查看>>
pstool 的使用方法
查看>>
Email - Boss's concerns
查看>>
余世维 - 有效沟通
查看>>
mysql用户与权限管理笔记
查看>>
a里面不能嵌套a
查看>>
Myeclipse中打开接口实现类的快捷键
查看>>