搜索
热搜: NOIP OIer 神牛
查看: 282|回复: 0

1245小奇の迷宫捏

[复制链接]

主题

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2023-5-27 15:41:40 | 显示全部楼层 |阅读模式
#include<bits/stdc++.h>
using namespace std;
int n;
int ha,la,hb,lb;
char ch[110][110];
bool vis[110][110];
int dr[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct pos{
        int x;
        int y;
        int step;
};
bool f=false;
void bfs(){
        queue<pos>q;
        pos p;
        p.x=ha;
        p.y=la;
        p.step=0;
        vis[ha][la]=true;
        q.push(p);
        while(!q.empty()){
                p=q.front();
                q.pop();
                for(int i=0;i<4;i++){
                int nx=p.x+dr[i][0];
                int ny=p.y+dr[i][1];
                if(nx>=0&&nx<n&&ny>=0&&ny<n&&ch[nx][ny]=='.'&&!vis[nx][ny]){
                        vis[nx][ny]=true;
                        if(nx==hb&&ny==lb){
                                f=true;
                                return;
                        }
                        pos np;
                        np.x=nx;
                        np.y=ny;
                        np.step=p.step+1;
                        q.push(np);
                       
                        }
                }
        }
}
int main(){
        int k;
        cin>>k;
        while(k--){
                cin>>n;
                for(int i=0;i<n;i++){
                        for(int j=0;j<n;j++){
                                cin>>ch[i][j];
                        }
                }
                cin>>ha>>la>>hb>>lb;
                memset(vis,false,sizeof(vis));
                f=false;
                if(ch[ha][la]=='#'||ch[hb][lb]=='#'){
                        cout<<"NO"<<endl;
                }else{
                       
                        bfs();
                        if(f){
                                cout<<"YES"<<endl;
                        }else{
                                cout<<"NO"<<endl;
                        }
                }
        }
        return 0;
}

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

津ICP备19006949号-1 | 津公网安备12010102000465号

快速回复 返回顶部 返回列表