洛谷吧 关注:863贴子:2,622
  • 0回复贴,共1

离谱错误MLE,求助求助

只看楼主收藏回复

题目:洛谷P2360 地下城主
链接:https://www.luogu.com.cn/problem/P2360
```cpp
#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**)
求助求助!!!

现场.png


IP属地:北京1楼2025-01-23 22:16回复