BFS HDOJ 2102 A计划
题意:中文题面
分析:双层BFS,之前写过类似的题.总结坑点:
1.步数小于等于T都是YES 2. 传送门的另一侧还是传送门或者墙都会死 3. 走到传送门也需要一步
#include <bits/stdc++.h>
using namespace std; char maze[2][11][11];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int n, m, tot;
bool vis[2][11][11];
struct Point {
int x, y, z, step;
Point () {}
Point (int x, int y, int z, int step) : x (x), y (y), z (z), step (step) {}
};
Point s, e; bool check(int x, int y, int z) {
if (x < 1 || x > n || y < 1 || y > m || vis[z][x][y] || maze[z][x][y] == '*') return false;
else return true;
} bool BFS(void) {
memset (vis, false, sizeof (vis));
int res = 0x3f3f3f3f;
queue<Point> que; que.push (s);
vis[s.z][s.x][s.y] = true;
while (!que.empty ()) {
Point u = que.front (); que.pop ();
if (u.x == e.x && u.y == e.y && u.z == e.z) {
res = min (res, u.step); continue;
}
for (int i=0; i<4; ++i) {
int tx = u.x + dx[i], ty = u.y + dy[i], tz = u.z;
if (!check (tx, ty, tz)) continue;
if (maze[tz][tx][ty] == '#') {
if (maze[1-tz][tx][ty] == '*' || maze[1-tz][tx][ty] == '#' || vis[1-tz][tx][ty]) continue;
vis[1-tz][tx][ty] = true;
que.push (Point (tx, ty, 1 - tz, u.step + 1));
continue;
}
vis[tz][tx][ty] = true;
que.push (Point (tx, ty, tz, u.step + 1));
}
}
return res <= tot;
} int main(void) {
int T; scanf ("%d", &T);
while (T--) {
scanf ("%d%d%d", &n, &m, &tot);
for (int k=0; k<2; ++k) {
if (k == 1) getchar ();
for (int i=1; i<=n; ++i) {
scanf ("%s", maze[k][i] + 1);
for (int j=1; j<=m; ++j) {
if (maze[k][i][j] == 'S') {
s = Point (i, j, k, 0);
}
else if (maze[k][i][j] == 'P') {
e = Point (i, j, k, 0);
}
}
}
}
if (BFS ()) puts ("YES");
else puts ("NO");
} return 0;
}
BFS HDOJ 2102 A计划的更多相关文章
- HDOJ 2102 A计划(bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路分析: <1>搜索方法分析:由于需要寻找最短的找到公主的路径,所以采用bfs搜索 ...
- hdoj 2102 A计划
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdoj 2102 A计画 【BFS】
称号:hdoj 2102 A计画点击打开链接 意甲冠军:文的就不说了.求救出公主所须要的最短时间,所以用广搜. 分析:读题之后不难做,比一般的题目多了一个条件就是能够传送,那么我们能够在广搜里面加一个 ...
- HDU 2102 A计划(两层地图加时间限制加传送门的bfs)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others) Me ...
- hdu 2102 A计划
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
- BFS例题:A计划
ContribContrib/a11y/accessibility-menu.js 关于 BFS要点: 1.若为可化为的坐标系图形,可用结构体存储其x值,y值和步数.(一般开now 和 next ,n ...
- hdu - 2102 A计划 (简单bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...
- hdu 2102 A计划(双层BFS)(具体解释)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...
- HDU 2102 A计划(BFS/DFS走迷宫)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
随机推荐
- OSG osgDB FileUtils FileNameUtil操作文件名相关函数
/** Gets the parent path from full name (Ex: /a/b/c.Ext => /a/b). */extern OSGDB_EXPORT std::stri ...
- 安装jdk源码
step1:打开选择Window->Preference step2:选择Java->Installed JREs step3:选中你所安装的jre,点击Edit,进入Edit JRE,如 ...
- SOCKet 编程 简介
“一切皆Socket!” 话虽些许夸张,但是事实也是,现在的网络编程几乎都是用的socket. ——有感于实际编程和开源项目研究. 我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览 ...
- python如何一行输入多个值
python2的raw_input以及python3的input获取的是整行的字符串.读进来后,字符串有着著名的split可以根据分隔符拆解成子串组成的list. 对于list内的对象,需要的采取转换 ...
- IOS 开发,调用打电话,发短信,打开网址
IOS 开发,调用打电话,发短信,打开网址 1.调用 自带mail [[UIApplication sharedApplication] openURL:[NSURL URLWithString: ...
- ASP.NET MVC使用Bundle来打包压缩js和css
Bundle它是用来将js和css进行压缩(多个文件可以打包成一个文件),并且可以区分调试和非调试,在调试时不进行压缩,以原始方式显示出来,以方便查找问题. 1.BundleConfig配置Bundl ...
- 在Eclipse中自定义类似syso的快捷代码模板
sysout/syso syserr/ syse 点击菜单栏的“Window”->“Preferences”,打开“Preferences”对话框.在Preferences”对话框中点击“Jav ...
- 解决Pyqt打包后运行报错:应用程序无法启动 因为程序的并行配置不正确
做了一个生成二维码的小程序:http://www.cnblogs.com/dcb3688/p/4241048.html 直接运行脚本没问题,用pyinstaller打包后再运行就直接报错了: 应用程序 ...
- Oracle备份 还原命令
1.备份命令 exp username/password file=d:/test/test.dmp; 2.还原命令 imp username/password full=y file=d:/test ...
- 杂物 python (一)
python 是一门语言,有各种不同的实现.CPython 即用c语言实现Python及其解释器.