#4124. 广搜—最短路模版

广搜—最短路模版

#include iostream

#include queue

using namespace std;

char map[201][201];

bool vis[201][201];

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

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

int R, C, sx, sy;

struct Node {

    int x, y, step;

};

int bfs(int x, int y) {

    queue《Node》 q;

    q.push({x, y, 0});

    vis[x][y] = true;

    while (!q.empty()) {

        Node u = {{ input(3) }};

        q.pop();

        if (map[u.x][u.y] == 'E') {

            return {{ input(4) }};

        }

        for (int i = 0; i < 4; i++) {

            {{ input(5) }} ; 先?[?] + ?

            {{ input(6) }} ;

            if ({{ input(7) }}) //边界 先x后y 格式:? < ? || ? > ? || ? < ? || ? > ?

                continue;

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

                continue;

            vis[nx][ny] = true;

            q.push({nx, ny, {{ input(9) }}});

        }

    }

    return {{ input(10) }};

}

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(11) }};

    if (s == -1)

        cout << -1 << endl;

    else

        cout << s << endl;

    return 0;

}