#4125. 广搜—联通问题模版练习

广搜—联通问题模版练习

正确填写空白处所需的代码,注意认真观察定义的变量名

#include iostream

#include queue

using namespace std;

char map[201][201];

bool vis[201][201];

int xx[] = { {{ input(1) }} }; //填空1 x 方向移动 上下左右 格式为{?,?,?,?}

int yy[] = { {{ input(2) }} }; //填空2 y 方向移动

int R, C, sx, sy;

struct Node {

    int x, y;

};

int bfs(int x, int y) {

    {{ input(3) }} q; 填空3 创建队列

    q.push({x,y});

    vis[x][y] = true;

    while ({{ input(4) }}) { 填空4:循环条件

        Node u = q.front();

        q.pop();

        if (u.x == R && u.y == C) {

            return 1;

        }

        for (int i = 0; i < {{ input(5) }}; i++) {

            {{ input(6) }}; 填空6 新的x坐标

            {{ input(7) }}; 填空7 新的y坐标

            if (nx < 1 || nx > R || ny < 1 || ny > C)

                continue;

            if ({{ input(8) }}) //障碍物为#,#号不加引号,先障碍物后标记

                continue;

            vis[nx][ny] = true;

            q.push({{ input(9) }}); 填空9 放入新的坐标到队列中

        }

    }

    return -1;

}

int main() {

    cin >> R >> C;

    for (int i = 1; i <= R; i++) {

        for (int j = 1; j <= C; j++) {

            cin >> map[i][j];

            if (map[i][j] == 'S') {

                sx = i;

                sy = j;

            }

        }

    }

    int s = {{ input(10) }}; 填空10:调用搜索函数

    if (s == -1)

        cout << "NO" << endl;

    else

        cout << "YES" << endl;

    return 0;

}