WHAT WHY 啊~~~~

P1746 离开中山路

woyaoAKIOI0924PTY @ 2024-11-28 20:14:31

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=25;
struct Node{
    int x,y,step;
};
char ss[N][N];
int n,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
bool vis[N][N];
int sx,sy,tx,ty;
bool check(int x,int y)
{
    if(x<1||x>n||y<1||y>n)
        return 1;
    if(ss[x][y]=='#'||vis[x][y])
        return 1;
    return 0;
}
int bfs()
{
    queue<Node>q;
    vis[sx][sy]=1;
    q.push({sx,sy,0});
    while(q.size())
    {
        Node t=q.front();
        q.pop();
        if(t.x==tx&&t.y==ty)
            return t.step;
        for(int i=0;i<4;++i)
        {
            int px=t.x+dx[i],py=t.y+dy[i];
            if(check(px,py))    
                continue;
            vis[px][py]=true;
            q.push({px,py,t.step+1}); 
        }
    }
    return -1;
}
signed main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=n;++j)
        {
            cin>>ss[i][j];
            vis[i][j]=0;     
        }
    }
    cout<<bfs()<<"\n";
    return 0;
}

by woyaoAKIOI0924PTY @ 2024-11-28 21:00:01

_成功WA AC 了,正式宣布———此贴~结_


|