BFS40分求调!(悬关,先到先得)
查看原帖
BFS40分求调!(悬关,先到先得)
1004336
Hope5365楼主2023/10/20 19:27

蒟蒻自己写了一个BFS 40pts,求调(码风丑)(悬关)

#include <iostream>
#include <queue>
using namespace std;

const int N = 1e2 + 10;
bool mark[N][N],can[N][N];
int n,m,ans;

struct Bit
{
    int x,y;
};
queue <Bit> q;

void bfs()
{
    q.push({1,1});
    while (!q.empty())
    {
        Bit k = q.front();
        int x = k.x,y = k.y;
        q.pop();
        if (!can[x][y] || mark[x][y]) continue;
        if (x == n && y == m)
        {
            ans = 1;
            break;
        }
        mark[x][y] = 1;
        q.push({x + 1,y});
        q.push({x - 1,y});
        q.push({x,y + 1});
        q.push({x,y - 1});
    }
}

int main()
{
    cin >> n >> m;
    for(int i = 1;i <= n;i ++)
        for(int j = 1;j <= m;j ++)
        {
            char c;
            scanf("%c",&c);
            can[i][j] = (c == '.');
        }
    bfs();
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
2023/10/20 19:27
加载中...