当前位置:网站首页>uva11624 Fire! (双bfs)
uva11624 Fire! (双bfs)
2022-08-09 08:11:00 【51CTO】
Joe works in a maze. Unfortunately, portions of the maze have
caught on fire, and the owner of the maze neglected to create a fire
escape plan. Help Joe escape the maze.
Given Joe’s location in the maze and which squares of the maze
are on fire, you must determine whether Joe can exit the maze before
the fire reaches him, and how fast he can do it.
Joe and the fire each move one square per minute, vertically or
horizontally (not diagonally). The fire spreads all four directions
from each square that is on fire. Joe may exit the maze from any
square that borders the edge of the maze. Neither Joe nor the fire
may enter a square that is occupied by a wall.
Input
The first line of input contains a single integer, the number of test
cases to follow. The first line of each test case contains the two
integers R and C, separated by spaces, with 1 ≤ R, C ≤ 1000. The
following R lines of the test case each contain one row of the maze. Each of these lines contains exactly
C characters, and each of these characters is one of:
• #, a wall
• ., a passable square
• J, Joe’s initial position in the maze, which is a passable square
• F, a square that is on fire
There will be exactly one J in each test case.
Output
For each test case, output a single line containing ‘IMPOSSIBLE’ if Joe cannot exit the maze before the
fire reaches him, or an integer giving the earliest time Joe can safely exit the maze, in minutes.
Sample Input
2
4 4
####
#JF#
#..#
#..#
3 3
###
#J.
#.F
Sample Output
3
IMPOSSIBLE
题目链接
思路:由于题中没有说有几个起火点 所以 要用一个队列来维护。
当在T秒时人移动过后 对火点进行扩散
边栏推荐
猜你喜欢
随机推荐
继承中的运算符重载:输入输出的传奇
Result consisted of more than one row
The principle and configuration of VLAN
VLAN的原理及配置
MySql homework practice questions
Notes on OpenHarmony Open Source Meeting (Nanjing Station)
ncnn 推理猫狗识别
NAT地址转换的原理与配置
网络布线及数制转换
requests之模拟登录学习
Cookie和Session详解
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Visualize、HOOPS Publish
转换为onnx模型错误汇总
泛型和lambda表达式
传输层协议介绍
OpenHarmony开源见面会(南京站)相关笔记
MySQL数据库
【无标题】
路由配置转发及实验
IO byte stream reads text Chinese garbled

![【MySQL】mysql:解决[Err] 1093 - You can‘t specify target table ‘表名‘ for update in FROM clause问题](/img/76/8e6a3a1c5fdc9bffc0c7c9187a027c.png)







