每日训练 day 1

ACW 1096. 地牢大师

#include <bits/stdc++.h>
using namespace std;
const int N =150;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int l,r,c,d[N][N][N];
char g[N][N][N];
int dx[6]={1,-1,0,0,0,0};
int dy[6]={0,0,1,-1,0,0};
int dz[6]={0,0,0,0,1,-1};
void bfs(int x1,int y1,int z1){
    queue<tuple<int,int,int>>q;
    q.push({x1,y1,z1});
    memset(d,-1,sizeof d);
    d[x1][y1][z1]=0;
    while(!q.empty()) {
        auto t = q.front();
        q.pop();
        for (int i = 0; i <= 5; i++) {
            int x = get<0>(t) + dx[i], y = get<1>(t) + dy[i], z = get<2>(t) + dz[i];
            if (x >= 1 && x <= r && y >= 1 && y <= c && z >= 1 && z <= l && d[x][y][z] == -1 && g[x][y][z]=='.') {
                q.push({x, y, z});
                d[x][y][z] = d[get<0>(t)][get<1>(t)][get<2>(t)] + 1;
            }
        }
    }
}
signed main(){
    fast
    while(cin>>l>>r>>c,l&&r&&c){
        memset(g,0,sizeof g);
        int cnt=1,x1,y1,x2,y2,z1,z2;
        while(cnt){
            for(int i=1;i<=r;i++){
                for(int j=1;j<=c;j++){
                    char s;cin>>s;
                    if(s!='#')g[i][j][cnt]='.';
                    if(s=='S')x1=i,y1=j,z1=cnt;
                    if(s=='E')x2=i,y2=j,z2=cnt;
                }
            }
            cnt++;
            if(cnt==l+1)break;
        }
        bfs(x1,y1,z1);
        int t=d[x2][y2][z2];
        if(t==-1)cout<<"Trapped!"<<Endl;
        else cout<<"Escaped in "<<t<<" minute(s)."<<endl;
    }
    return 0^0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值