#1873. 珅泽教育CSP-J第一轮模拟考第十套 第 42 题

珅泽教育CSP-J第一轮模拟考第十套 第 42 题

第2题

给定一个 N×MN \times M 的迷宫网格(含不可通行的 #、可通行的 .、双向必传送且耗时 00 的滑梯对(大写字母)、出口 = 和起点 @),从起点出发,移动相邻草地耗时 11,传送耗时 00。计算从起点到达出口所需的最短时间。

#include<iostream>
char a[1000][1000];
int d[1000][1000];
int n, m;
int qx[1000*1000];
int qy[1000*1000];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sumx[26];
int sumy[26];
void bfs(int x, int y) {
    qx[0] = x;
    qy[0] = y;
    d[x][y] = 1;
    int head = 0;
    int tail = 1;
    while (head < tail) {
        int x = qx[____(1)____];
        int y = qy[____(2)____];
        ____(3)____++;
        for (int k = 0; k < 4; ++k) {
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (____(4)____) {
                if (____(5)____) continue;

                if ('A' <= a[nx][ny] and a[nx][ny] <= 'Z') {
                    char c = a[nx][ny];
                    nx = ____(6)____ ;
                    ny = ____(7)____ ;
                }

                if ( ____(8)____ ) {
                    d[nx][ny] = ____(9)____ ;
                    qx[tail] = nx;
                    qy[tail] = ny;
                    tail++;
                }
            }
        }
    }
}

int main()
{
    std::cin >> n >> m;
    int sx, sy, tx, ty;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
            std::cin >> a[i][j];
            if (a[i][j] == '@') {sx = i; sy = j;}
            if (a[i][j] == '=') {tx = i; ty = j;}
            if ('A' <= a[i][j] and a[i][j] <= 'Z') {
                sumx[a[i][j] - 'A'] += i;
                sumy[a[i][j] - 'A'] += j;
            }
        }
    bfs(sx, sy);
    std::cout << ____(10)____ << "\n";
}

(4)(5) 处应填( )。

{{ select(1) }}

  • 0 <= nx or nx < n or 0 <= ny or ny < m, a[nx][ny] == '#'
  • 0 <= nx and nx < n and 0 <= ny and ny < m, a[nx][ny] != '#'
  • 0 <= nx or nx < n or 0 <= ny or ny < m, a[nx][ny] != '#'
  • 0 <= nx and nx < n and 0 <= ny and ny < m, a[nx][ny] == '#'