题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=2102

A计划

Description

可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。
现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。

Input

输入的第一行C表示共有C个测试数据,每个测试数据的前一行有三个整数N,M,T。 N,M迷宫的大小N*M(1 <= N,M <=10)。T如上所意。接下去的前N*M表示迷宫的第一层的布置情况,后N*M表示迷宫第二层的布置情况。

Output

如果骑士们能够在T时刻能找到公主就输出“YES”,否则输出“NO”。

Sample Input

1
5 5 14
S*#*.
.#...
.....
****.
...#.

..*.P
#.*..
***..
...*.
*.#..

Sample Output

YES

双层bfs。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::map;
using std::pair;
using std::queue;
using std::vector;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef unsigned long long ull;
bool vis[][N][N];
char G[][N][N];
int H, W, T;
const int dx[] = { , , -, }, dy[] = { -, , , };
struct Node {
int c, x, y, s;
Node(int i = , int j = , int k = , int l = ) :c(i), x(j), y(k), s(l) {}
};
bool bfs() {
cls(vis, false);
queue<Node> q;
q.push(Node());
vis[][][] = true;
while (!q.empty()) {
Node t = q.front(); q.pop();
if (G[t.c][t.x][t.y] == 'P') return t.s <= T;
rep(i, ) {
int nx = t.x + dx[i], ny = t.y + dy[i];
char &ch = G[t.c][nx][ny];
if (nx < || nx >= H || ny < || ny >= W ) continue;
if (ch == '*' || vis[t.c][nx][ny]) continue;
if (ch == '#') {
if (G[t.c ^ ][nx][ny] == '#' || G[t.c ^ ][nx][ny] == '*') continue;
if (vis[t.c ^ ][nx][ny]) continue;
q.push(Node(t.c ^ , nx, ny, t.s + ));
vis[t.c ^ ][nx][ny] = vis[t.c][nx][ny] = true;
continue;
}
q.push(Node(t.c, nx, ny, t.s + ));
vis[t.c][nx][ny] = true;
}
}
return false;
}
inline void input(bool d) {
rep(i, H) scanf("%s", G[d][i]);
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) {
scanf("%d %d %d", &H, &W, &T);
input(), input();
puts(bfs() ? "YES" : "NO");
}
return ;
}

最新文章

  1. 合并文件夹里多个excel
  2. Delphi 获取系统时间后格式化输出
  3. Codeforces Round #348(VK Cup 2016 - Round 2)
  4. 简单的session共享的封装
  5. python 与 mysql
  6. URAL 1012 K-based Numbers. Version 2(DP+高精度)
  7. Linux查看系统版本信息的
  8. 06 Theory of Generalization
  9. php实现301跳转
  10. UIEvent&amp;nbsp;UIResponder&amp;nbsp;UI_04
  11. [Swift]LeetCode363. 矩形区域不超过 K 的最大数值和 | Max Sum of Rectangle No Larger Than K
  12. Mongodb到mysql数据库的数据迁移(Java,Windows)
  13. spring boot + vue + element-ui全栈开发入门——集成element-ui
  14. C# Interview Question 1
  15. unix缓冲
  16. python标准库介绍——29 zlib 模块详解
  17. 手机e.pageX和e.pageY无效的原因
  18. 服务器的日志一直报Packet for query is too large (7632997 &gt; 4194304). You can change this value on the server by setting the max_allowed_packet&#39; variable.的解决方法
  19. Java Web相关技术(汇聚页)
  20. UBB/HTML互相转换简单实现源码一览

热门文章

  1. 解决visual studio已安装的问题
  2. 在代码中调用 mvc 4 api
  3. rsync 参数断点续传
  4. linux下LAMP环境搭建尝试
  5. SQL:每年每月最高的两个温度
  6. 在Win7下要通过某个 线程 来调用SavaDialog文件选择框的问题
  7. [转]回答--python django学的很迷茫怎么办?
  8. sql server命名规范
  9. C# 加密算法
  10. Xcode Alcatraz插件管理介绍和使用