http://poj.org/problem?id=2157
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
/*
这里只要判断yes or no,故BFS所有能到达的位置,只要注意当出队的是门时,若不能打开,
则不做操作让门重新入队,避免死循环,这里用limit进行限制
*/
using namespace std;
struct node
{
int x,y;
node(int a=0,int b=0){x=a;y=b;}
};
int limit,m,n,key[5],vis[20][20];
int move[4][2]={0,1,1,0,0,-1,-1,0};
char maze[20][20];
bool bfs(int x,int y)
{
queue<node> que;
node p;
limit=0;
que.push(node(x,y));
while(!que.empty()&&limit<400)
{
limit++;
p=que.front();
que.pop();
if(maze[p.x][p.y]>='A'&&
这篇博客详细介绍了如何使用宽度优先搜索(BFS)解决POJ 2157题目的迷宫问题。通过算法解析和示例,展示了如何在给定的迷宫中找到从起点到终点的最短路径。
订阅专栏 解锁全文
546

被折叠的 条评论
为什么被折叠?



