poj 22515 Dungeon Master
2015-08-06 16:06
232 查看
DungeonMaster
Description
Youaretrappedina3Ddungeonandneedtofindthequickestwayout!Thedungeoniscomposedofunitcubeswhichmayormaynotbefilledwithrock.Ittakesoneminutetomoveoneunitnorth,south,east,west,upordown.You
cannotmovediagonallyandthemazeissurroundedbysolidrockonallsides.
Isanescapepossible?Ifyes,howlongwillittake?
Input
Theinputconsistsofanumberofdungeons.EachdungeondescriptionstartswithalinecontainingthreeintegersL,RandC(alllimitedto30insize).
Listhenumberoflevelsmakingupthedungeon.
RandCarethenumberofrowsandcolumnsmakinguptheplanofeachlevel.
ThentherewillfollowLblocksofRlineseachcontainingCcharacters.Eachcharacterdescribesonecellofthedungeon.Acellfullofrockisindicatedbya'#'andemptycellsarerepresentedbya'.'.Yourstartingpositionisindicatedby'S'andthe
exitbytheletter'E'.There'sasingleblanklineaftereachlevel.InputisterminatedbythreezeroesforL,RandC.
Output
Eachmazegeneratesonelineofoutput.Ifitispossibletoreachtheexit,printalineoftheform
Escapedinxminute(s).
wherexisreplacedbytheshortesttimeittakestoescape.
Ifitisnotpossibletoescape,printtheline
Trapped!
SampleInput
SampleOutput
[/code]
TimeLimit:1000MS | MemoryLimit:65536K | |
TotalSubmissions:20926 | Accepted:8110 |
Youaretrappedina3Ddungeonandneedtofindthequickestwayout!Thedungeoniscomposedofunitcubeswhichmayormaynotbefilledwithrock.Ittakesoneminutetomoveoneunitnorth,south,east,west,upordown.You
cannotmovediagonallyandthemazeissurroundedbysolidrockonallsides.
Isanescapepossible?Ifyes,howlongwillittake?
Input
Theinputconsistsofanumberofdungeons.EachdungeondescriptionstartswithalinecontainingthreeintegersL,RandC(alllimitedto30insize).
Listhenumberoflevelsmakingupthedungeon.
RandCarethenumberofrowsandcolumnsmakinguptheplanofeachlevel.
ThentherewillfollowLblocksofRlineseachcontainingCcharacters.Eachcharacterdescribesonecellofthedungeon.Acellfullofrockisindicatedbya'#'andemptycellsarerepresentedbya'.'.Yourstartingpositionisindicatedby'S'andthe
exitbytheletter'E'.There'sasingleblanklineaftereachlevel.InputisterminatedbythreezeroesforL,RandC.
Output
Eachmazegeneratesonelineofoutput.Ifitispossibletoreachtheexit,printalineoftheform
Escapedinxminute(s).
wherexisreplacedbytheshortesttimeittakestoescape.
Ifitisnotpossibletoescape,printtheline
Trapped!
SampleInput
345 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 133 S## #E# ### 000
SampleOutput
Escapedin11minute(s). Trapped!
bfs:
代码:
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
usingnamespacestd;
structrecord
{
intx,y,z;//坐标;
inttime;//时间;
};
intvis[35][35][35];
chars[35][35][35];
intdx[6]={-1,0,0,1,0,0};//六个方向;
intdy[6]={0,-1,0,0,1,0};
intdz[6]={0,0,-1,0,0,1};
intl,r,c;
intx1,y1,z1;
queue<record>q;
intjudge(recorde)//判断该位置是否符合条件;
{
if(e.x<0||e.x>=l||e.y<0||e.y>=r||e.z<0||e.z>=c||vis[e.x][e.y][e.z]||s[e.x][e.y][e.z]=='#')
{
return0;
}
return1;
}
voidbfs()
{
recorde,temp;
inti;
while(!q.empty())//清空队列;
{
q.pop();
}
vis[x1][y1][z1]=1;//标记为被访问过;
e.x=x1;
e.y=y1;
e.z=z1;
e.time=0;//从(x1,y1,z1)开始,时间首先定为0;
q.push(e);//将可以走的位置插入到队列中;
while(!q.empty())//如果队列不为空;
{
e=q.front();//e设为队列的第一个元素;
q.pop();//取出第一个元素;
for(i=0;i<6;i++)//六个方向进行搜索;
{
temp=e;
temp.x+=dx[i];
temp.y+=dy[i];
temp.z+=dz[i];
temp.time=e.time+1;//时间+1;
if(!judge(temp))//不满足条件跳出本次循环
{
continue;
}
if(s[temp.x][temp.y][temp.z]=='E')//遇到出口输出;
{
printf("Escapedin%dminute(s).\n",temp.time);
return;
}
vis[temp.x][temp.y][temp.z]=1;//标记该位置已访问;
q.push(temp);
}
}
printf("Trapped!\n");
}
intmain()
{
inti,j,k,key;
while(scanf("%d%d%d",&l,&r,&c)!=EOF&&l||r||c)
{
memset(vis,0,sizeof(vis));
for(i=0;i<l;i++)
{
for(j=0;j<r;j++)
{
scanf("%s",s[i][j]);
}
}
for(i=0;i<l;i++)
{
for(j=0;j<r;j++)
{
for(k=0;k<c;k++)
{
if(s[i][j][k]=='S')
{
x1=i;y1=j;z1=k;
}
}
}
}
bfs();
}
return0;
}
[/code]
相关文章推荐
- bzoj2066: [Poi2004]Gra
- Linux 磁盘挂载共享
- Session and cookie
- 用getchar和putchar输入输出字符
- Eclipse配置Github实现版本控制
- NSNotification(通知中心)传值
- git merge
- Visual Studio 监视与快速监视即时窗口没有智能提示
- [转]C# 系统应用之鼠标模拟技术及自动操作鼠标
- scala入门1
- 离开时验证思路
- 第7章 线程调度、优先级和亲缘性(1)
- 【Jsoup网页解析】
- JS childNodes属性
- 文件服务器配置案例--需求描述(一)
- 原生js获取鼠标坐标方法全面讲解:clientX/Y,pageX/Y,offsetX/Y,layerX/Y,screenX/Y
- Podfile.lock: No such file or directory
- jQuery插件reel3D展示
- codeforces 343c Read Time
- Android开发问题集合