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 ...
随机推荐
- 多文件上传CommonsMultipartResolver
1.CommonsMultipartResolver是spring里面提供的一个上传方式,效率我不知道,但是加入spring容器管理还是很不错的. 2.先看依赖包pom.xml <project ...
- Maven pom.xml 常用打包配置
<build> <!-- 指定JAVA源文件目录 --> <sourceDirectory>src</sourceDirectory> <!-- ...
- JavaScript中的attachEvent和addEventListener
attachEvent和addEventListener在前端开发过程中经常性的使用,他们都可以用来绑定脚本事件,取代在html中写obj.onclick=method. 相同点: 它们都是dom对象 ...
- JavaScript常用类
JS常用类 一.Number 1.常用数字 整数:10 小数:3.14 科学计数法:1e5 | 1e-5 正负无穷:Infinity | -Infinity 2.常用进制 二进制:0b1010 八进制 ...
- Android热修复 Dex注入实现静默消灭bug
当app上线后发现紧急bug,如果重新发布版本周期比较长,并且对用户体验不好,此时热修复就派上用场了.热修复就是为紧急bug而生,能够快速修复bug,并且用户无感知.针对热修复,阿里系先后推出AndF ...
- 【Udacity】异常值检测/删除
Outlier Detection
- 【Python】list和tuple 区别比较
列表 List classmates = ['Michael', 'Bob', 'Tracy'] 元组 Tuple tuple一旦初始化就不能修改,比如同样是列出同学的名字: >>> ...
- Junit 报错: Failed to load ApplicationContext
今天在使用Junit测试时候,报了个错误: Failed to load ApplicationContext, aspect not found;挺奇怪的 我又没有调用你,之前还好好的,现在不能使用 ...
- C#复制粘贴
用C#程序复制粘贴非常简单,这里为了实用,只介绍对文字的操作,其他情况类似: Clipboard.SetText(“我是需要复制到系统剪贴板的文字”); 执行以上代码后,即可ctrl+V进行粘贴.是不 ...
- SQL Server ->> 与SQL Server服务配置相关的DMV
1) sys.dm_server_services这个DMV可以告诉我们与当前版本的SQL Server相关的服务的启动状态和最后一次启动的时间,诸如这样的信息. SELECT * FROM sys. ...