HDU 2102 A计划(两层地图加时间限制加传送门的bfs)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=2102
A计划
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 28972 Accepted Submission(s): 7274
现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。
5 5 14
S*#*.
.#...
.....
****.
...#.
..*.P
#.*..
***..
...*.
*.#..
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <cstdlib>
#include <queue>
using namespace std;
#define max_v 105
struct node
{
int x,y,step,type;
};
char G[][][];
int n,m,t;
int dir[][]={,,,,-,,,-};
int bfs(int sx,int sy)
{
queue<node> q;
node p,next; p.x=sx;
p.y=sy;
p.step=;
p.type=; q.push(p); while(!q.empty())
{
p=q.front();
q.pop(); if(G[p.type][p.x][p.y]=='*')//当前位置 墙
continue; if(G[p.type][p.x][p.y]=='P')//找到公主
return ; G[p.type][p.x][p.y]='*';//走过标记 for(int i=;i<;i++)
{
next.x=p.x+dir[i][];
next.y=p.y+dir[i][];
next.step=p.step+;
next.type=p.type; if(next.step>t||G[next.type][next.x][next.y]=='*')//下一个位置超时 或者是墙
continue; if(G[next.type][next.x][next.y]=='#')//下一个位置是传送门
{
G[next.type][next.x][next.y]='*';//标记走过 next.type=-next.type;//传送门对应层的位置 if(G[next.type][next.x][next.y]=='#'||G[next.type][next.x][next.y]=='*')//传送门对应层是传送门或者墙
{
G[next.type][next.x][next.y]=G[-next.type][next.x][next.y]='*';//两个图对应的位置都标记
continue;
}
}
q.push(next);
}
}
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
cin>>n>>m>>t;
memset(G,'*',sizeof(G));
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
cin>>G[][i][j];
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
cin>>G[][i][j];
}
}
if(bfs(,))
printf("YES\n");
else
printf("NO\n");
}
return ;
}
HDU 2102 A计划(两层地图加时间限制加传送门的bfs)的更多相关文章
- HDU 2102 A计划 DFS与BFS两种写法 [搜索]
1.题意:一位公主被困在迷宫里,一位勇士前去营救,迷宫为两层,规模为N*M,迷宫入口为(0,0,0),公主的位置用'P'标记:迷宫内,'.'表示空地,'*'表示墙,特殊的,'#'表示时空传输机,走到这 ...
- hdu 2102 A计划
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
- hdu 2102 A计划(双层BFS)(具体解释)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...
- [HDU 2102] A计划(搜索题,典型dfs or bfs)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 2102 A计划(BFS/DFS走迷宫)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU 2102 A计划(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...
- HDU 2102 A计划 (BFS)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 2102 A计划-bfs
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- HDU 2102 A计划 经典搜索
A计划 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
随机推荐
- Web开发:Bootstrap的应用
- HDU 3191 次短路长度和条数
http://www.cnblogs.com/wally/archive/2013/04/16/3024490.html http://blog.csdn.net/me4546/article/det ...
- LinearLayout中的android:layout_garvity的center_vertical和center_horizontal
当LinearLayout的排列方向是 horizontal时,只有垂直方向上的对齐方式才会生效.因为此时水平方向上的长度是不固定的,每添加一个控件,水平方向上的长度都会改变,因而无法指定该方向上的对 ...
- Android xmlns 的作用及其自定义
转自:http://blog.csdn.net/chuchu521/article/details/8052855 xmlns:Android="http://schemas.android ...
- 在mysql语句中为什么要加反引号
在MySQL语句中我们有时候经常会遇到反引号(``),刚开始的时候不知道什么意思,他是什么作用呢? Select * from `member` order by posts desc limit 0 ...
- 为什么分布式一定要有redis?(转)
为什么分布式一定要有redis? 程序员小灰 6天前 点击上方“程序员小灰”,选择“置顶公众号” 有趣有内涵的文章第一时间送达! 作者:孤独烟 来自:http://rjzheng.cnblogs.co ...
- csharp: Request.Form,Request.QueryString,Request.Params,Request.Cookies
/// <summary> /// Request.Form,Request.QueryString,Request.Params /// http://msdn.microsoft.co ...
- Web前端面试指导(十三):css样式的优先级是怎么样的?
题目点评 CSS样式的优先级规则给人的感觉总是摸不透,更不用说怎么去表达了,在网络上流传着很多版本,描述的都很复杂也不全面,看了之后还是不满意.我来给大家介绍一个比较系统.全面有比较容易记住的规则吧! ...
- 清楚苹果 iPai端按钮默认样式
input[type="button"], input[type="submit"], input[type="reset"] { -web ...
- OpenCV中Mat属性step,size,step1,elemSize,elemSize1
Mat的step,size,step1,elemSize,elemSize1这几个属性非常容易混淆. OpenCV的官方参考手册也没有解释清楚这几个概念. 前一段时间研究了一下每个属性的含义,如果有什 ...