poj 3984 迷宫问题 学会了一招计算路径
来源:互联网 发布:混油皮水乳推荐知乎 编辑:程序博客网 时间:2024/04/29 08:58
#include<iostream>
using namespace std;
#include<queue>
int a[5][5];
int dir[4][2]={0,1,1,0,-1,0,0,-1};
int map[5][5];
void bfs(int x,int y)
{
queue<int> q;
q.push(x);
q.push(y);
//system("pause");
while(!q.empty())
{
int m=q.front();q.pop();
int n=q.front();q.pop();
//cout<<m<<' '<<n;
//system("pause");
for(int i=0;i<4;i++)
{
int mm=m+dir[i][1];
int nn=n+dir[i][0];
if(mm==4 && nn==4)
{
map[mm][nn]=m*5+n;
// cout<<map[mm][nn];
// system("pause");
return ;
}
if(mm>=0 && mm<=4 && nn>=0 && nn<=4 && a[mm][nn]!=1)
{
q.push(mm);
q.push(nn);
map[mm][nn]=(5*m+n);//计算路径的好方法
a[mm][nn]=1;
}
}
}
}
void print(int i,int j)
{
//cout<<map[i][j]<<' '<<j<<endl;
//system("pause");
if(i==0&&j==0)
{
printf("(0, 0)/n");
return ;
}
print(map[i][j]/5,map[i][j]%5);
printf("(%d, %d)/n",i,j);
}
int main()
{
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
cin>>a[i][j];
}
}
bfs(0,0);
print(4,4);
//system("pause");
return 0;
}
- poj 3984 迷宫问题 学会了一招计算路径
- poj 3984 迷宫问题(BFS+输出路径)
- POJ 3984:迷宫问题(BFS+路径记录)
- POJ 3984 迷宫问题 (路径记录)
- POJ 3984 迷宫问题 BFS 记录路径
- poj 3984 迷宫问题 bfs输出路径
- POJ 3984--迷宫问题【BFS && 记录路径】
- poj 3984 迷宫问题【bfs+输出路径】
- poj 3984 迷宫问题(BFS+输出路径)
- poj 3984 迷宫问题 【bfs + 路径记录】
- POJ 3984迷宫问题(记录路径)
- poj 3984 迷宫问题【dfs+路径输出】
- POJ 3984 迷宫问题 BFS+记录路径
- POJ 3984 迷宫问题 【BFS+路径记录】
- 【BFS+保存路径】POJ 3984 迷宫问题
- poj 3984 迷宫问题 BFS+路径记录
- poj 3984 迷宫问题 dfs 求迷宫路径
- POJ 3984 迷宫问题【迷宫最短路径 bfs】
- Unix&Linux大学教程:13使用shell:命令和定制
- DataSet中的一些简单的基本的操作
- 最后90天
- JAVA SE Lesson 2
- ubuntu中 OPERO的 GPG 校验签名出错 NO_PUBKEY的解决办法
- poj 3984 迷宫问题 学会了一招计算路径
- ALV :汇总,分类汇总(小计),排序,过滤
- VC对话框界面如何调整静态文本字体和大小?(转载)
- hook资料
- Maqetta(HTML5可视化开发工具)下载和安装
- 保存table
- 关于开机启动运行的注册表操作(MFC)
- (三)二元查找树转换双向链表
- VS 2005 中使用 VC6.0中编写的Project 若干问题(08应该也可以)