全部评论 1

  • #include<bits/stdc++.h>
    using namespace std;
    int n,sx,sy,fx,fy;
    char mp[110][110];
    struct node{int x;int y;};
    bool v[110][110],f=false;
    int d[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
    queue<node>q;
    void bfs(){
    if(mp[sx][sy]'#'||mp[fx][fy]'#'){
    while(!q.empty())q.pop();
    f=false;
    return;}
    while(!q.empty()){
    node t=q.front();
    q.pop();
    int xx=t.x,yy=t.y;
    if(xxfx&&yyfy){
    f=true;
    return;}
    for(int i=0;i<4;i++){
    int nx=xx+d[i][0];
    int ny=yy+d[i][1];
    if(nx>=0&&nx<n&&ny>=0&&ny<n&&mp[nx][ny]!='#'&&v[nx][ny]false){
    v[nx][ny]=true;
    q.push({nx,ny});}}}}
    int main(){
    freopen("path.in","r",stdin);
    freopen("path.out","w",stdout);
    int a;
    cin>>a;
    for(int r=1;r<=a;r++){
    cin>>n;
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
    cin>>mp[i][j];
    memset(v,0,sizeof v);
    cin>>sx>>sy>>fx>>fy;
    q.push({sx,sy});
    bfs();
    if(f
    true)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    f=false;}
    return 0;
    fclose(stdin);
    fclose(stdout);}

    2024-08-09 来自 浙江

    0

热门讨论