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;
}
转载于:https://www.cnblogs.com/Running-Time/p/4982500.html
BFS HDOJ 2102 A计划相关推荐
- HDU - 2102 A计划(双层BFS)
题目: 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国王正是心急如焚, ...
- Aquarius's Trial F - 6 HDU - 2102 A计划
A计划 Problem Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的 ...
- HDU 2102 A计划
该题是一道典型的搜索题, #include<stdio.h> #include<stdlib.h> #include<string.h> struct Node { ...
- BFS HDOJ 1242 Rescue
题目传送门 题意:从r走到a,遇到x多走一步,问最小走到a的步数 分析:因为r有多个,反过来想从a走到某个r的最小步数,简单的BFS.我对这题有特殊的感情,去年刚来集训队时肉鸽推荐了这题,当时什么都不 ...
- HDU 2102 A计划(广度优先搜索+数据)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDOJ 1010 HDU 1010 Tempter of the Bone ACM 1010 IN HDU
MiYu原创, 转帖请注明 : 转载自 ______________白白の屋 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述: 代码 ...
- hdu1010 Tempter of the Bone
转载自:http://acm.hdu.edu.cn/forum/read.php?tid=6158 sample input: 4 4 5 S.X. ..X. ..XD .... 问题: (1): 在 ...
- HDU-基础搜索总结
Dfs: 1241 Oil Deposits 题解:https://blog.csdn.net/HeZhiYing_/article/details/81053035 1016 Prime Ring ...
- 搜索专题(不定期更新)
1.POJ 2386 Lake Counting 题意:给出一块区域,询问有多少个湖泊? 思路:DFS,对于'W',深搜一次,并标记已访问.之后每次对未访问的'W'做一次深搜. 1 #include ...
最新文章
- C++:随笔4--对象
- JavaScript学习笔记(5)
- Problem 2. number题解
- (王道408考研数据结构)第八章排序-第五节:归并排序
- 全视频沟通不再远 罗技为中国企业开启视频协作新格局
- asio几种异步编程模型
- npm使用及cmd常用命令
- Spark亚太研究院王家林:从技术的…
- 居民身份证号码的编码规则
- 使用web3.py获取zkSync中的数据
- SEO中的简单代码优化
- Visual C++编译错误:error C2220: 警告被视为错误 - 没有生成“object”文件
- 售前工程师的成长---一个老员工的经验之谈(二)(转载)
- PS基础-day03套索,魔棒,裁剪,修复画笔工具组,蒙版
- 如何找出1000以内的“完数“
- 安装windows远程桌面服务器,如何安装应用,以便在 Windows Server 远程桌面服务中使用...
- 计算机怎么删除我的苹果设备管理器,怎么删除电脑我的苹果设备管理器
- linksys 打印软件_评论:Linksys WRT1900AC双无线路由器是WRT54G的第二代产品
- Linux安装gpm(实现Linux复制粘贴)
- Linux-Journal