当前位置:网站首页>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秒时人移动过后 对火点进行扩散
边栏推荐
猜你喜欢

Dark Horse 2022 latest redis course notes and knowledge points (for interview)

System Security and Application

Routing configuration forwarding and experiment

账号和权限管理

.net(一)WebService创建

世界顶尖3D Web端渲染引擎:HOOPS Communicator技术介绍(一)

引导过程与服务控制

Shell编程之正则表达式

Object detection app based on appinventor and EasyDL object detection API

SOLIDWORKS Simulation教程:计算物体的固有频率
随机推荐
IO byte stream reads text Chinese garbled
动态设置img标签图片失效问题
鸿蒙开发实战一——手表篇
eTS UI开发学习
6000 字+,帮你搞懂互联网架构演变历程!
Redis redis 】 【 the expiration of listening
204. 数素数
编程洗衣机:字符串输出后的乱码
实现弹簧柔性状态的2种方式 | Solidworks教程
VMware虚拟机强制关闭后,无法联网
Servlet详解
Euclid and the game
Result consisted of more than one row
消息中间件(MQ)前置知识介绍(必看)
Literature retrieval operation code
交换机基本原理与配置
数据库中的操作(语法)
A watch - article HongMeng development practical experience
Different styles of Flask-restful
3D精彩案例,清软英泰建成综合轻量化显示平台!