⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4795524_re.cpp

📁 部分PKU上的源码
💻 CPP
字号:
#include<iostream>
using namespace std;
struct point
{
	int x,y,z;
	int step;
};
char map[32][32][32];
bool used[32][32][32];
int l,r,c;
int sz,sx,sy,ez,ex,ey;
int xm[6]={0,0,1,-1,0,0};
int ym[6]={1,-1,0,0,0,0};
int zm[6]={0,0,0,0,1,-1};
bool bfs()
{
	int head=0,tail=1;
	point q[3000];
	q[0].x=sx;q[0].y=sy;q[0].z=sz;q[0].step=0;
	used[sz][sx][sy]=true;
	while(head<tail)
	{
		point t=q[head];
		for(int count=0;count<6;count++)
		{
			if(t.x+xm[count]>=0&&t.x+xm[count]<r&&
				t.y+ym[count]>=0&&t.y+ym[count]<c&&
				t.z+zm[count]>=0&&t.z+zm[count]<l)
			{
				switch(map[t.z+zm[count]][t.x+xm[count]][t.y+ym[count]])
				{
				case'E': printf("Escaped in %d minute(s).\n",t.step+1);return true;
				case '.':
					if(used[t.z+zm[count]][t.x+xm[count]][t.y+ym[count]]==false)
					{
						used[t.z+zm[count]][t.x+xm[count]][t.y+ym[count]]=true;
						q[tail].x=t.x+xm[count];
						q[tail].y=t.y+ym[count];
						q[tail].z=t.z+zm[count];
						q[tail].step=t.step+1;
						tail++;
					}
				}
			}
		}
		head++;
	}
	return false;
}
int main()
{
	while(cin>>l>>r>>c)
	{
		if(l==0&&r==0&&c==0) return 0;
		int i,j,k;
		for(i=0;i<l;i++)
			for(j=0;j<r;j++)
				for(k=0;k<c;k++)
				{
					cin>>map[i][j][k];
					switch(map[i][j][k]) 
					{
					case 'S':sz=i;sx=j;sy=k;break;
					case 'E':ez=i;ex=j;ey=k;break;
					}
				}
		memset(used,false,sizeof(used));
		if(!bfs()) printf("Trapped!\n");
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -