求调
  • 板块P1605 迷宫
  • 楼主no_oier
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/3/30 17:13
  • 上次更新2024/3/30 17:17:42
查看原帖
求调
1034661
no_oier楼主2024/3/30 17:13
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main () {
    int n, m, t;
    cin >> n >> m >> t;
    int x, y, x1, y1;
    cin >> x >> y >> x1 >> y1;
    queue<pair<int, int>> q;
    q.emplace(x, y);
    vector<vector<bool>> maze(n + 1, vector<bool>(m + 1, false));
    maze[x][y] = true;
    for (int i = 1; i <= t; ++i) {
        int x2, y2;
        cin >> x2 >> y2;
        maze[x2][y2] = true;
    }
    
    int dx[] = {0, 0, -1, 1};
    int dy[] = {1, -1, 0, 0};
    int res = 0;
    while (!q.empty()) {
        auto t = q.front();
        q.pop();
        if (t.first == x1 && t.second == y1) {
            res++; 
        }
        for (int i = 0; i < 4; ++i) {
            int tx = t.first + dx[i];
            int ty = t.second + dy[i];
            if (maze[tx][ty] != true && tx <= n && ty <= m && tx >= 1 && ty >= 1) {
                q.emplace(tx, ty);
                maze[tx][ty] = true;
            }
        }
    }
    cout << res << endl; 
    return 0;
}
2024/3/30 17:13
加载中...