【站外题求助】一本通1248:Dungeon Master 编译错误
  • 板块学术版
  • 楼主zhaoxuchun
  • 当前回复10
  • 已保存回复10
  • 发布时间2022/12/4 10:16
  • 上次更新2023/10/27 00:33:00
查看原帖
【站外题求助】一本通1248:Dungeon Master 编译错误
602367
zhaoxuchun楼主2022/12/4 10:16
#include <bits/stdc++.h>
using namespace std;
int u,v,w,mp[1005][1005][1005];
int jx,jy,jz,tx,ty,tz;
char c;
bool f;
int dx[6]={0,0,1,-1,0,0},dy[6]={1,-1,0,0,0,0},dz[6]={0,0,0,0,1,-1};
struct h{
   int x,y,z,bs;
}hp[1001000];
void bfs(){
    int head=1;
    int tail=1;
    hp[head].x=jx;
    hp[head].y=jy;
    hp[head].z=jz;
    hp[head].bs=0;
    mp[jx][jy][jz]=1;
    while(head<=tail){
        for(int i=0;i<6;i++){
            int x1=hp[head].x+dx[i];
            int y1=hp[head].y+dy[i];
            int z1=hp[head].z+dz[i];
            if(x1>=1&&x1<=u&&y1>=1&&y1<=v&&z1>=1&&z1<=w&&mp[x1][y1][z1]==0){
                tail++;
                hp[tail].x=x1;
                hp[tail].y=y1;
                hp[tail].z=z1;
                hp[tail].bs=hp[head].bs+1;
                mp[x1][y1][z1]=1;
            }
            if(x1==tx&&y1==ty&&z1==tz){
                f=true;
                cout<<"Escaped in "<<hp[tail].bs<<" minute(s)."<<endl;
                return;
            }
        }
        head++;
    }   
}
int main(){
	while(1){
		cin>>u>>v>>w;
		if(u==0&&v==0&&w==0){
			break;
		}
		f=false;
		memset(mp,0,sizeof(mp));
		for(int i=1;i<=u;i++){
			for(int j=1;j<=v;j++){
				for(int k=1;k<=w;k++){
					cin>>c;
					if(c=='#'){
						mp[i][j][k]=1;
					}
                    if(c=='S'){
                 	   	jx=i;
                	    jy=j;
                	    jz=k;
                	}
                	if(c=='E'){
                	  	tx=i;
                	    ty=j;
                	    tz=k;
                	}
				}
			}
		}
		bfs();
        if(f==false){
            cout<<"Trapped!"<<endl;
        }
	}
	return 0;
}

代码只有75行,但编译器显示我有200多行,请问是为什么?

2022/12/4 10:16
加载中...