WA40pts,求助
查看原帖
WA40pts,求助
932039
lzy20091001楼主2023/8/17 16:26

https://www.luogu.com.cn/record/121418150

我连个橙题都做不对了

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

const int dir[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};

struct node
{
    int dep, x, y, z;
};

int l, r, c, tx, ty, tz;
char mp[50][50][50];
bool vis[50][50][50];
queue <node> q;

void bfs()
{
    while (!q.empty())
    {
        node tmp = q.front();
        q.pop();
        if (tmp.x == tx && tmp.y == ty && tmp.z == tz)
        {
            cout << "Escaped in " << tmp.dep << " minute(s)." << "\n";
            return;
        }
        for (int i = 0; i < 6; i++)
        {
            int nx = tmp.x + dir[i][0], ny = tmp.y + dir[i][1], nz = tmp.z + dir[i][2];
            if (0 <= nx && nx <= l && 0 <= ny && ny <= r && 0 <= nz && nz <= c && mp[nx][ny][nz] != '#' && !vis[nx][ny][nz])
            {
                vis[nx][ny][nz] = true;
                q.push({tmp.dep + 1, nx, ny, nz});
            }
        }
    }
    cout << "Trapped!" << "\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> l >> r >> c;
    for (int i = 1; i <= l; i++)
        for (int j = 1; j <= r; j++)
            for (int k = 1; k <= c; k++)
            {
                cin >> mp[i][j][k];
                if (mp[i][j][k] == 'S')
                {
                    q.push({0, i, j, k});
                    vis[i][j][k] = true;
                    // cout << i << " " << j << " " << k << "\n";
                }
                else if (mp[i][j][k] == 'E')
                    tx = i, ty = j, tz = k;
            }
    bfs();
    // cout << "Trapped!" << "\n";
    // cout << i << " " << j << " " << k << "\n";
    // cout << tx << " " << ty << " " << tz;
    return 0;
}

2023/8/17 16:26
加载中...