60求助
查看原帖
60求助
1310428
违规用户名1310428楼主2024/5/3 17:46

3,5WA

#include<bits/stdc++.h>
using namespace std;
int n,m,l,d=9999999;
string maze[35][35];
bool vis[35][35][35];
bool in(int x,int y,int z) {
    return 0<=x&&x<n&&0<=y&&y<m&&0<=z&&z<l;
}
void dfs(int x,int y,int z,int c) {  
    if(in(x,y,z)==0||maze[z][x][y]=='#'||vis[z][x][y]==1||c>=d)return;
    if(maze[z][x][y]=='E'){
        d=min(d,c);
        return;
    }
    vis[z][x][y]=1;
    dfs(x,y+1,z,c+1); 
    dfs(x+1,y,z,c+1); 
    dfs(x,y-1,z,c+1); 
    dfs(x-1,y,z,c+1);
    dfs(x,y,z-1,c+1); 
    dfs(x,y,z+1,c+1);
    return;
}
int main() {
    cin>>l>>n>>m;
    for (int i=0;i<l;i++){
        for (int j=0;j<n;j++){
            cin>>maze[i][j];
        }
    }
    for (int z=0;z<l;z++){
        for (int i=0;i<n;i++){
            for (int j=0;j<m;j++){
                if(maze[z][i][j]== 'S'){
                    dfs(i,j,z,0);
                    if(d==9999999)cout<<"Trapped!";
                    else cout<<"Escaped in "<<d<<" minute(s).";
                    return 0;
                }
            }
        }
    }
    return 0;
}
2024/5/3 17:46
加载中...