POJ3984 迷宫问题【BFS】

题目链接:

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define maxn 50
int a[5][5];
int dis[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int front=0;
int rear=0;
int visit[5][5];
struct node{
    int x,y;
    int pre;
}Node[maxn];
void dfs(int beginX,int beginY,int endX,int endY)
{
    Node[0].x=beginX;
    Node[0].y=beginY;
    Node[0].pre=-1;
    visit[beginX][beginY]=1;
    rear++;
    while (front4||newY<0||newY>4||visit[newX][newY]==1||a[newX][newY]==1)
                continue;
            Node[rear].x=newX;
            Node[rear].y=newY;
            Node[rear].pre=front;
            visit[newX][newY]=1;
            rear++;
            if(newX==endX&&newY==endY)
                return;
        }
        front++;
    }
}
void print(node now)
{
    if(now.pre==-1)
        cout<<"("<>a[i][j];
        }
    }
    dfs(0, 0, 4, 4);
    print(Node[rear-1]);
    return 0;
}

 

你可能感兴趣的:(poj,BFS)