HDU_3085 Nightmare Ⅱ(噩梦)

小夜曲在梦中和他的女朋友被困在一个大迷宫中,两人分别与两个幽灵周旋。他们需要在幽灵找到他们之前相遇。小夜曲每秒可以移动3步,他的女朋友每秒移动1步,而幽灵会不断分裂占领周围2格。题目要求找出他们在最短时间内的相遇可能性。输入包含迷宫大小和布局,保证各角色唯一。输出为最小相遇时间或失败的-1。

噩梦

链接

HDU_3085 Nightmare Ⅱ(噩梦)

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

Output

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值