广搜之鸣人与佐助

广搜之鸣人与佐助_第1张图片

#include
#include 
#include 
#include 
using namespace std;
int M,N,T;
char Map[205][205];
int visited[205][205][15];
int dx[]={1,-1,0,0};
int dy[] = {0,0,1,-1};
struct node
{
    int x,y,time,ckl;
    node(int xx,int yy,int tt,int cc):x(xx),y(yy),time(tt),ckl(cc) {};
    node() {}
};
queue q;
int main()
{
    cin >> M >> N >> T;
    node mingren,zuozhu;
    memset(visited,1,sizeof(visited));
    for(int i=1; i<=M; i++)
        for(int j=1; j<=N; j++)
        {
            cin >> Map[i][j];
            if(Map[i][j]=='@')
            {
                mingren=node(i,j,0,T);
            }
            else if(Map[i][j]=='+')
            {
                Map[i][j]='*';
                zuozhu=node(i,j,-1,-1);
            }
            for(int t=0; t<=T; t++)
                visited[i][j][t]=0;
        }
    q.push(mingren);
    visited[mingren.x][mingren.y][mingren.ckl]=1;
    while(!q.empty())
    {
        node now = q.front();
        if(now.x==zuozhu.x && now.y==zuozhu.y)
        {
            cout<0&&endx<=M&&endy>0&&endy<=N && Map[endx][endy]=='*' &&!visited[endx][endy][now.ckl])
            {
                q.push(node(endx,endy,now.time+1,now.ckl));
                visited[endx][endy][now.ckl] = 1;
            }
            if(endx>0&&endx<=M&&endy>0&&endy<=N&&Map[endx][endy]=='#' && (now.ckl>0) &&(!visited[endx][endy][now.ckl-1]))
            {
                q.push(node(endx,endy,now.time+1,now.ckl-1));
                visited[endx][endy][now.ckl-1] = 1;
            }
        }

    }
    cout<<-1<

你可能感兴趣的:(搜索,广度优先搜索,图)