当前位置:网站首页>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秒时人移动过后 对火点进行扩散
边栏推荐
猜你喜欢
随机推荐
LAN Technology - 6MSTP
3D软件开发工具HOOPS全套产品开发介绍 | HOOPS Exchange、HOOPS Communicator
Redis(八)集群
Database MySQL installation and uninstallation
安全的Md5加密:两次加密(加盐)
Different styles of Flask-restful
Redis redis 】 【 the expiration of listening
OSI网络模型
Shell编程之正则表达式
静态路由的原理与配置
鸿蒙开发实战一——手表篇
Introduction to the Endpoint
3D精彩案例,清软英泰建成综合轻量化显示平台!
pip3 source change to improve speed
Analysis that may result in a savecount of 0 in Loadrunner checkpoints
MySql homework practice questions
CUDA和cuDNN 安装10.0版本
Cookie and Session Details
Three handshakes, four waves
Process synchronization and mutual exclusion problem