HDU 3085 - Nightmare Ⅱ - []

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3085

Problem Description
Last night, little erriyue had a horrible nightmare. He dreamed that he and his girl friend were trapped in a big maze separately. More terribly, there are two ghosts in the maze. They will kill the people. Now little erriyue wants to know if he could find his girl friend before the ghosts find them.
You may suppose that little erriyue and his girl friend can move in 4 directions. In each second, little erriyue can move 3 steps and his girl friend can move 1 step. The ghosts are evil, every second they will divide into several parts to occupy the grids within 2 steps to them until they occupy the whole maze. You can suppose that at every second the ghosts divide firstly then the little erriyue and his girl friend start to move, and if little erriyue or his girl friend arrive at a grid with a ghost, they will die.
Note: the new ghosts also can devide as the original ghost.

Input
The input starts with an integer T, means the number of test cases.
Each test case starts with a line contains two integers n and m, means the size of the maze. (1<n, m<800)
The next n lines describe the maze. Each line contains m characters. The characters may be:
‘.’ denotes an empty place, all can walk on.
‘X’ denotes a wall, only people can’t walk on.
‘M’ denotes little erriyue
‘G’ denotes the girl friend.
‘Z’ denotes the ghosts.
It is guaranteed that will contain exactly one letter M, one letter G and two letters Z.

Output
Output a single integer S in one line, denotes erriyue and his girlfriend will meet in the minimum time S if they can meet successfully, or output -1 denotes they failed to meet.

Sample Input
3
5 6
XXXXXX
XZ..ZX
XXXXXX
M.G...
......
5 6
XXXXXX
XZZ..X
XXXXXX
M.....
..G...

10 10
..........
..X.......
..M.X...X.
X.........
.X..X.X.X.
.........X
..XX....X.
X....G...X
...ZX.X...
...Z..X..X

Sample Output
1
1
-1

题意:

给定 $n \times m$ 的地图,现在地图上一些格子是墙,人不能通过。地图上有一个男孩和一个女孩,男孩一次能朝一个方向跑 $3$ 格,女孩一次能朝一个方向跑 $1$ 格。

现在地图上有两个幽灵,幽灵每秒钟可以向四周扩撒 $2$ 格,被扩散的格子都会变成有幽灵的,墙不能阻挡幽灵,它们会一直扩散知道遍布整个地图。

假设每个单位时间内,都是幽灵先于男孩女孩移动。现在问你男孩和女孩在不碰到幽灵的前提下,能不能会和在一个格子。

题解:

原文地址:https://www.cnblogs.com/dilthey/p/10029673.html

时间: 2024-08-02 08:52:44

HDU 3085 - Nightmare Ⅱ - []的相关文章

HDU 3085 Nightmare Ⅱ (双向广搜)

题意:有M,G两人和鬼魂(Z)在n*m的方格内,M每秒走3步,G每秒走一步,鬼魂每秒走2步,问是否能 不遇到鬼魂下两人相遇,鬼魂可以穿墙(X),人不可以.初始鬼魂有2个. #include<stdio.h> #include<string.h> #include<string> #include<queue> #include<map> #include<iostream> #include<algorithm> #def

HDU 3085 Nightmare Ⅱ【BFS +曼哈顿距离+综合性较强】

Nightmare Ⅱ Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 16   Accepted Submission(s) : 6 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Last night, little erriyue

HDU 1072 Nightmare (BFS)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1072 题目大意: 走迷宫,初始剩余时间为6min,每步1min:到reset区是若剩余时间大于0,则可以重置.到终点3区,若时间大于0,则成功逃脱.(可以走回路) 0:wall 1:可以走 2:起点 3:终点 4:剩余时间重置为6 源代码: #include<iostream> #include<cstring> #include<cstdio> #include<q

kuangbin专题 专题二 搜索进阶 Nightmare Ⅱ HDU - 3085

题目链接:https://vjudge.net/problem/HDU-3085 题意:有两个鬼和两个人和墙,鬼先走,人再走,鬼每走过的地方都会复制一个新鬼, 但新鬼只能等待旧鬼走完一次行程之后,下一次旧鬼再次开始新的行程时旧鬼才能移动, 旧鬼一个行程能走最多两步,M能走三步,G能走一步. 问M和G能不能在被鬼抓住之前相遇,求最短时间. ‘Z’表示鬼. 第一次用曼哈顿距离来真正解决搜索,参考过别人的代码,这份代码感觉还是比较清楚和简单的. 人每次移动一个距离都要进行一次曼哈顿距离的判断,判断人到

hdu 1072 Nightmare BFS,第一次刷BFS的题,感好牛逼的。。。

Nightmare Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7758    Accepted Submission(s): 3723 Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth with a ti

HDU 1072 Nightmare(BFS)

Nightmare Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9120    Accepted Submission(s): 4389 Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth with a ti

HDU 1072 Nightmare( 身上带有定时炸弹的他能否在炸弹爆炸之前离开—— BFS+DP思想)

Nightmare Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the

【HDOJ】3085 Nightmare Ⅱ

双向BFS.注意,任何一个点出队后,首先需要考虑ghost. 1 /* 3085 */ 2 #include <iostream> 3 #include <queue> 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 using namespace std; 9 10 #define MAXN 805 11 12 ty

hdu - 1240 Nightmare &amp;&amp; hdu - 1253 胜利大逃亡(bfs)

http://acm.hdu.edu.cn/showproblem.php?pid=1240 开始没仔细看题,看懂了发现就是一个裸的bfs,注意坐标是三维的,然后每次可以扩展出6个方向. 第一维代表在第几层.后两维代表行和列. 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 struct point 6 { 7 int x,y,z,step; 8 b