走迷宫 回溯法
来源:互联网 发布:软件行业净利润率 编辑:程序博客网 时间:2024/06/10 04:06
#include <iostream>
#include <windows.h>
using namespace std;
#define FINISH_X 4
#define FINISH_Y 11
#define M 1000
char a[12][12] = {{'#','#','#','#','#','#','#','#','#','#','#','#'},
{'#',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#'},
{'+',' ','#',' ','#',' ','#','#','#','#',' ','#'},
{'#','#','#',' ','#',' ',' ',' ',' ','#',' ','#'},
{'#',' ',' ',' ',' ','#','#','#',' ','#',' ',' '},
{'#','#','#','#',' ','#',' ','#',' ','#',' ','#'},
{'#',' ',' ','#',' ','#',' ','#',' ','#',' ','#'},
{'#','#',' ','#',' ','#',' ','#',' ','#',' ','#'},
{'#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','#'},
{'#','#','#','#','#','#',' ','#','#','#',' ','#'},
{'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ','#'},
{'#','#','#','#','#','#','#','#','#','#','#','#'},
};
int horizotal[4]={-1,1,0,0};
int vertical[4] = {0,0,-1,1};
void display()
{
system("cls");
int i,j;
for(i=0;i<12;i++)
{
for(j=0;j<12;j++)
cout << a[i][j] << ' ';
cout << endl;
}
}
void backtrack(int x,int y)
{
if(x==FINISH_X&&y==FINISH_Y)
{
cout << "Success " << endl;
system("pause");
exit(0) ;
}
else
{
int i;
a[x][y] = '+';
display();
Sleep(M);
for(i=0;i<4;i++)
{
if(a[x+vertical[i]][y+horizotal[i]]==' ')
backtrack(x+vertical[i],y+horizotal[i]);
}//for
a[x][y] = ' ';
display();
Sleep(M);
}//else
}
int main()
{
backtrack(2,0);
system("pause");
return 0;
}
- 走迷宫 回溯法
- 寒假补充项目-回溯法走迷宫
- 走迷宫回溯算法
- 回溯走迷宫
- 走迷宫问题:回溯法和递归法
- 第二十四周项目2-回溯法走迷宫
- 二十四周项目二--回溯法之走迷宫
- 用回溯法走迷宫,较简易代码
- 走迷宫回溯算法(Java实现)
- 迷宫问题 回溯法
- 回溯法-迷宫问题
- 回溯法迷宫求解
- 回溯法求迷宫
- 2014秋C++第19周 补充代码 回溯法走迷宫
- 迷宫走法
- 迷宫走法
- 回溯法求迷宫问题
- 回溯法解迷宫问题
- web自动安装脚本(apache/nginx+php+mysql)
- hash 使用
- 局域网内共享文件 提示没有访问权限的问题-转载于http://www.pcdog.com/a/29/10/i232880.html
- 用grep查询数组
- 习惯一切~
- 走迷宫 回溯法
- C#开机、注销、关机源码!
- 使用jdbc连接mysql 出现 java.sql.Exception: this specifer does...(root@'%')..doesn't exist.
- 有关我在SSHD(SSH三大框架和DWR框架)整合过程中出现的中文乱码问题的解决
- 一步一步教你安装Nginx+PHP+Mysql
- 没有SIM卡,GPRS模块也可以获取信号强度吗?
- 想要回头
- 喜欢的经典话语
- imp 用法