/**
***= =最近懒得没有发表一篇文章,自觉羞愧...于是发表几篇小文以弥胡哥对我的期盼之情...
翻译一下: 一个房间,3维的,指定他的3个维度的大小,然后指定他的每个单位的内容(= =w 天哪poj你好烦),#代表该单位无法通过,.代表可以通过,S代表可怜的主人公所在位置,E代表光明的出口所在的位置。求该主人公能否逃脱,能在最少多少次的操作后逃脱(话说这题翻译过来是地下城...好吧,槽点略多)
描述
You are trapped in a 3D dungeon and need to find the quickest way out!
The dungeon is composed of unit cubes which may or may not be filled with rock.
It takes one minute to move one unit north, south, east, west, up or down.
You cannot move diagonally and the maze is surrounded by solid rock on all sides.
Is an escape possible? If yes, how long will it take?
输入
The input consists of a number of dungeons.
Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon.
A cell full of rock is indicated by a '#' and empty cells are represented by a '.'.
Your starting position is indicated by 'S' and the exit by the letter 'E'.
There's a single blank line after each level.
Input is terminated by three zeroes for L, R and C.
输出
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
样例输入
3 4 5
S....
.###.
.##..
###.#
#####
#####
##.##
##...
#####
#####
#.###
####E
1 3 3
S##
#E#
###
0 0 0
样例输出
Escaped in 11 minute(s).
Trapped!
*/
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
using namespace std;
//
class Point{
public:
Point(int x,int y,int z){
this->x = x;
this->y = y;
this->z = z;
}
bool equals(Point p){
return (x==p.x && y==p.y && z==p.z);
}
int x;
int y;
int z;
};
void test(int L,int R,int C){
if(L<=30 && R<=30 && C<=30){//万恶的英语,题目limit to是<=的意思
int ROOM[L][R][C];
int NUMofS = 0;//S的个数
int NUMofE = 0;//E的个数
bool able = true;//此属性决定了该输入能否进行,包含了格式输出错误,个数错误等情况
int x0,y0,z0;//主人公的位置
int x1,y1,z1; //出口的位置
string s;
memset(ROOM,0,sizeof(ROOM));//将所有的内容都赋予0值
for(int i = 0;i < L;i++){
for(int j = 0;j < R;j++){
cin>>s;
if(s.length()>C)able = false;
for(int k = 0;k < C;k++){
char ch = s.at(k);//通过输入的字符来决定该位置的内容值
switch(ch){
case '#' :
ROOM[i][j][k] = -1;//-1即无法通过
break;
case '.' ://可以通过,默认为0
break;
case 'S' :
x0 = i;
y0 = j;
z0 = k;
NUMofS++;
if(NUMofS>1)
able = false;
break;
case 'E' :
x1 = i;
y1 = j;
z1 = k;
NUMofE++;
if(NUMofE>1)
able = false;
break;
default :
able = false;
}
}
}
}
if(able == false){//感觉题目设置的不严谨,因为输入格式错误的话,题目没有说明要怎么解决,不过经过多次的wa测试,上述情况应该输出无法通过的语句
cout<<"Trapped!"<<endl;
return;
}
Point from(x0,y0,z0);
Point to(x1,y1,z1);
queue<Point> p;
p.push(from);
while(!p.empty()){
Point xp = p.front();
p.pop();
if(xp.equals(to)){//搜到了相同的点就输出
cout<<"Escaped in "<<ROOM[to.x][to.y][to.z]<<" minute(s)."<<endl;
return;
}else{
for(int i = 0;i < 6;i++){
switch(i){
case 0 ://x方向-1
if(xp.x-1>=0 && !ROOM[xp.x-1][xp.y][xp.z]){
Point np(xp.x-1,xp.y,xp.z);
if(!np.equals(from)){
p.push(np);
ROOM[np.x][np.y][np.z] = ROOM[xp.x][xp.y][xp.z]+1;
}
}
break;
case 1 ://x方向+1
if(xp.x+1<L && !ROOM[xp.x+1][xp.y][xp.z]){
Point np(xp.x+1,xp.y,xp.z);
if(!np.equals(from)){
p.push(np);
ROOM[np.x][np.y][np.z] = ROOM[xp.x][xp.y][xp.z]+1;
}
}
break;
case 2 ://y方向-1
if(xp.y-1>=0 && !ROOM[xp.x][xp.y-1][xp.z]){
Point np(xp.x,xp.y-1,xp.z);
if(!np.equals(from)){
p.push(np);
ROOM[np.x][np.y][np.z] = ROOM[xp.x][xp.y][xp.z]+1;
}
}
break;
case 3 ://y方向+1
if(xp.y+1<R && !ROOM[xp.x][xp.y+1][xp.z]){
Point np(xp.x,xp.y+1,xp.z);
if(!np.equals(from)){
p.push(np);
ROOM[np.x][np.y][np.z] = ROOM[xp.x][xp.y][xp.z]+1;
}
}
break;
case 4 ://z方向-1
if(xp.z-1>=0 && !ROOM[xp.x][xp.y][xp.z-1]){
Point np(xp.x,xp.y,xp.z-1);
if(!np.equals(from)){
p.push(np);
ROOM[np.x][np.y][np.z] = ROOM[xp.x][xp.y][xp.z]+1;
}
}
break;
case 5 ://z方向+1
if(xp.z+1<C && !ROOM[xp.x][xp.y][xp.z+1]){
Point np(xp.x,xp.y,xp.z+1);
if(!np.equals(from)){
p.push(np);
ROOM[np.x][np.y][np.z] = ROOM[xp.x][xp.y][xp.z]+1;
}
}
break;
default :
cout<<"Trapped!"<<endl;
return;
}
}
}
}
cout<<"Trapped!"<<endl;
}
}
int main(){
int L,R,C;
cin>>L>>R>>C;
while(L&&R&&C){
test(L,R,C);
cin>>L>>R>>C;
}
return 0;
}
相关推荐
- **1+1>2**(选项C):CS(Customer Satisfaction)和CIS(Corporate Identity System)的结合能够产生大于两者之和的效果。 #### 10. 移动商务价值的核心 - **渠道**(选项C):在4P(产品、价格、渠道、促销)中...
- **程序存储与自动执行**:冯·诺依曼体系结构强调程序存储的概念,即程序和数据存储在同一存储器内,从而实现计算机无需人工干预就能自动执行程序的能力。(D) #### 网络软件 - **网络操作系统**:网络操作系统...
- **中断的概念**:硬件故障、程序异常等触发的中断事件。 - **中断处理流程**:中断请求、中断响应、中断服务、中断返回。 **19. 面向对象特性** - **选项分析**: - A. 正确,继承性是面向对象编程的核心特性...
学生将学习如何设计和实现类,以及如何通过对象间的交互来解决问题。 3. **异常处理**:Java中的异常处理机制允许程序员编写健壮的代码,能够捕获和处理运行时可能出现的问题。 4. **集合框架**:Java集合框架包括...
嵌入式八股文面试题库资料知识宝典-华为的面试试题.zip
训练导控系统设计.pdf
嵌入式八股文面试题库资料知识宝典-网络编程.zip
人脸转正GAN模型的高效压缩.pdf
少儿编程scratch项目源代码文件案例素材-几何冲刺 转瞬即逝.zip
少儿编程scratch项目源代码文件案例素材-鸡蛋.zip
嵌入式系统_USB设备枚举与HID通信_CH559单片机USB主机键盘鼠标复合设备控制_基于CH559单片机的USB主机模式设备枚举与键盘鼠标数据收发系统支持复合设备识别与HID
嵌入式八股文面试题库资料知识宝典-linux常见面试题.zip
面向智慧工地的压力机在线数据的预警应用开发.pdf
基于Unity3D的鱼类运动行为可视化研究.pdf
少儿编程scratch项目源代码文件案例素材-霍格沃茨魔法学校.zip
少儿编程scratch项目源代码文件案例素材-金币冲刺.zip
内容概要:本文深入探讨了HarmonyOS编译构建子系统的作用及其技术细节。作为鸿蒙操作系统背后的关键技术之一,编译构建子系统通过GN和Ninja工具实现了高效的源代码到机器代码的转换,确保了系统的稳定性和性能优化。该系统不仅支持多系统版本构建、芯片厂商定制,还具备强大的调试与维护能力。其高效编译速度、灵活性和可扩展性使其在华为设备和其他智能终端中发挥了重要作用。文章还比较了HarmonyOS编译构建子系统与安卓和iOS编译系统的异同,并展望了其未来的发展趋势和技术演进方向。; 适合人群:对操作系统底层技术感兴趣的开发者、工程师和技术爱好者。; 使用场景及目标:①了解HarmonyOS编译构建子系统的基本概念和工作原理;②掌握其在不同设备上的应用和优化策略;③对比HarmonyOS与安卓、iOS编译系统的差异;④探索其未来发展方向和技术演进路径。; 其他说明:本文详细介绍了HarmonyOS编译构建子系统的架构设计、核心功能和实际应用案例,强调了其在万物互联时代的重要性和潜力。阅读时建议重点关注编译构建子系统的独特优势及其对鸿蒙生态系统的深远影响。
嵌入式八股文面试题库资料知识宝典-奇虎360 2015校园招聘C++研发工程师笔试题.zip
嵌入式八股文面试题库资料知识宝典-腾讯2014校园招聘C语言笔试题(附答案).zip
双种群变异策略改进RWCE算法优化换热网络.pdf