其他分享
首页 > 其他分享> > 【codevs1215】迷宫

【codevs1215】迷宫

作者:互联网

problem

solution

codes

#include<iostream>
#include<queue>
using namespace std;
struct xyz{
    int x, y;
    xyz(int x = 0, int y = 0):x(x),y(y){};
};
int m, n, book[20][20];
char a[20][20];
const int dx[] = {0,1,-1,0};
const int dy[] = {1,0,0,-1};
int main(){
    cin>>m;
    while(m--){
        cin>>n;
        for(int i = 0; i < n; i++)cin>>a[i];
        bool ok = false;
        queue<xyz>q;  q.push(xyz(0,0));
        while(!q.empty()){
            xyz t = q.front();  q.pop();
            book[t.x][t.y] = 1;
            if(t.x==n-1 && t.y==n-1){ ok = true; break;}
            for(int i = 0; i < 4; i++){
                int newx = t.x+dx[i], newy = t.y+dy[i];
                if(newx>=0 && newx<n && newy>=0 && newy<n && (a[newx][newy]=='.'||a[newx][newy]=='e') && !book[newx][newy])
                    { book[newx][newy] = 1; q.push(xyz(newx, newy)); }
            }
        }
        if(ok)cout<<"YES\n";else cout<<"NO\n";
    }
    return 0;
}

 

标签:20,int,xyz,codevs1215,迷宫,cin,newx,&&
来源: https://www.cnblogs.com/gwj13114/p/15555959.html