40分求助,离谱
查看原帖
40分求助,离谱
1495945
qetuo20110101楼主2025/1/23 22:19
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;
int l,r,c,b[32][32][32];
int sx,sy,sz,ex,ey,ez,flag = 0;
int d[6][3] = {{0,-1,0},{0,0,1},{0,1,0},{0,0,-1},{1,0,0},{-1,0,0}};
char a[32][32][32];
struct pot{
	int x,y,z,cou;
};
queue<pot> q;
int checkA(int x,int y,int z){
	if(x >= 1 && x <= l && y >= 1 && y <= r && z >= 1 && z <= c && a[x][y][z] != '#' && b[x][y][z] == 0) return 1;
	return 0;
}
void bfs(pot st){
	pot now,next;
	st.cou = 0;
	b[st.x][st.y][st.z] = 1;
	q.push(st);
	while(!q.empty()){
		now = q.front();
		if(now.x == ex && now.y == ey && now.z == ez){
			flag = 1;
			cout << "Escaped in " << now.cou << " minute(s).";
			return;
		}
		for(int k = 0;k < 6;k++){
			next.x = now.x + d[k][0];
			next.y = now.y + d[k][1];
			next.z = now.z + d[k][2];
			next.cou = now.cou + 1;
			if(checkA(next.x,next.y,next.z)){
				b[next.x][next.y][next.z] == 1;
				q.push(next);
			}
		}
		q.pop();
	}
}
int main(){
	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 >> a[i][j][k];
				if(a[i][j][k] == 'S'){
					sx = i;
					sy = j;
					sz = k;
				}
				if(a[i][j][k] == 'E'){
					ex = i;
					ey = j;
					ez = k;
				}
			}
		}
	}
	pot st;
	st.x = sx;
	st.y = sy;
	st.z = sz;
	bfs(st);
	if(flag == 0){
		cout << "Trapped!";
	}
	return 0;
}

40分,2点AC,3点MLE (我想破脑袋都没想到为何是MLE

求助求助!!!

附件现场

2025/1/23 22:19
加载中...