当前位置:网站首页>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秒时人移动过后 对火点进行扩散
边栏推荐
猜你喜欢
随机推荐
204. Count Primes
Cookie和Session详解
RAID配置实战
Database MySQL installation and uninstallation
可能导致Loadrunner检查点中savecount为0的分析
黑马2022最新redis课程笔记知识点(面试用)
交换机基本原理与配置
Non-decreasing Array
世界顶尖3D Web端渲染引擎:HOOPS Communicator技术介绍(一)
【redis】redis之过期监听
MySQL数据库
【MySQL】mysql:解决[Err] 1093 - You can‘t specify target table ‘表名‘ for update in FROM clause问题
Decimal工具类
Different styles of Flask-restful
研发分享:机器学习卡片的使用
引导过程与服务控制
不同风格的Flask-restful
数据库中的操作(语法)
204. 数素数
Shell编程之正则表达式