hdu 2102 A计划
题目连接
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 ;
}
hdu 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计划 (简单bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...
- hdu 2102 A计划(优先队列+dfs)
改了好久,上午来实验室打出来了,运行就是不对,一直找啊找!还是没找到,最后突然停电了,打好的代码还没保存呢! 刚才来的时候又重新打了一遍!!!结果一个小小的错误wrong了好久!!! 在dfs值返回时 ...
- 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】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...
- HDU 2102 A计划 (BFS)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 模糊查询(LIKE)and (PATINDEX() . CHARINDEX())
SQL中的模糊查询一般来说使用模糊查询,大家都会想到LIKE select * from table where a like '%字符%' 如果一个SQL语句中用多个 like模糊查询,并且记录条 ...
- 查看linux占用内存/CPU最多的进程
可以使用一下命令查使用内存最多的10个进程 ps -aux | sort -k4nr | head -n 10 可以使用一下命令查使用CPU最多的10个进程 ps -aux | sort -k3nr ...
- Android WebView与JavaScript交互操作(Demo)
应用场景: 为了使Android移动项目能够在较短的时间内完成开发,同时降低技术人员开发的成本投入,往往会采用Hybrid APP的开发模式.相关Hybrid APP(混合型应用)参看:http:// ...
- 记录网上资源URL
FQ(使用路由器): http://kennylee26.iteye.com/blog/1887753 http://www.iteye.com/search?type=all&query=s ...
- windows内核对象可以等待
内核对象有两种状态 触发 与未触发. 是可以等待的.
- Android控件大全(三)——RecyclerView
是时候用RecyclerView来替换ListView和GridView了 好处就不多说了,百度一搜一大把,来介绍下用法 先定义个适配器: public class BottomSheetAdapte ...
- IT职场求生法则(转)
摘要:在IT职场打滚超过10年了,从小小的程序员做到常务副总.相对于其它行业,IT职场应该算比较光明的了,但也陷阱重重,本文说说我的亲身体会,希望大家能在IT职场上战无不胜! 作者:张传波 软件知识大 ...
- CuteFTP 9.0 上传文件时,中文文件名乱码
解决办法如图: 1.右键--->属性 2.选项---->档案名称编 选择ascⅡ
- Windows下WEB服务器的选择与搭建
本文主要基于支持perl的web服务器的选择. 一直基于web开发,服务器都是linux下使用webmin搭建的,惭愧的说一句,这么多年,也好好研究过WEB服务器,单从这个角度,是不是可以反应出web ...
- MySQL语法
sql(structure query language)结构化查询语言ansi iso/iec组织制定ddl(data definition language) 数据定义语言dml(manipula ...