Fire

传送门UVA11624

描述

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.

输入

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:

1
2
3
4
1. #, a wall
2. ., a passable square
3. J, Joe’s initial position in the maze, which is a passable square
4. F, a square that is on fire

There will be exactly one J in each test case.

输出

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.

样例

  • Input

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    2
    4 4
    ####
    #JF#
    #..#
    #..#
    3 3
    ###
    #J.
    #.F
  • Output

    1
    2
    3
    IMPOSSIBLE

题解

  • 题意:迷宫逃脱,一开始有多个火焰源,火焰每单位时间向四周蔓延一格,人每单位可以向四周移动一格,人可以从任意边界逃脱,但是不能碰到火焰,求最短逃脱时间。
  • 先多起点bfs预处理出每一个格子的火焰到达时间,然后对人进行bfs即可。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<stdio.h>
#include<string.h>
#include<queue>
#define INIT(a,b) memset(a,b,sizeof(a))
#define LL long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e3+7;
const int mod=1e9+7;
int t,n,m,jx,jy;
char mp[N][N];
int fi[N][N],vis[N][N];
int rec[4][2]={1,0,-1,0,0,1,0,-1};
struct node{
int x,y,time;
};
inline bool away(int i,int j){
if(i==0||i==n-1||j==0||j==m-1)return true;
else return false;
}
inline bool judge(int i,int j){
if(i<0||i>=n||j<0||j>=m||vis[i][j]||mp[i][j]=='#')return false;
return true;
}
queue<node> fque;
void fire(){
while(!fque.empty()){
node q=fque.front();fque.pop();
for(int i=0;i<4;i++){
int nx=q.x+rec[i][0],ny=q.y+rec[i][1];
if(judge(nx,ny)){
fque.push((node){nx,ny,q.time+1});
fi[nx][ny]=q.time+1;
vis[nx][ny]=1;
}
}
}
}
int bfs(){
INIT(vis,0);
queue<node> que;
que.push((node){jx,jy,1});
vis[jx][jy]=1;
while(!que.empty()){
node q=que.front();que.pop();
if(away(q.x,q.y)) return q.time;
for(int i=0;i<4;i++){
int nx=q.x+rec[i][0],ny=q.y+rec[i][1];
if(judge(nx,ny)&&q.time+1<fi[nx][ny]){
que.push((node){nx,ny,q.time+1});
vis[nx][ny]=1;
}
}
}
return -1;
}
int main(){
scanf("%d",&t);
while(t--){
INIT(fi,inf),INIT(vis,0);
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++){
getchar();
for(int j=0;j<m;j++){
scanf("%c",&mp[i][j]);
if(mp[i][j]=='J') jx=i,jy=j;
if(mp[i][j]=='F') {
fque.push((node){i,j,1});
vis[i][j]=1;
fi[i][j]=1;
}
}
}
fire();
int ans=bfs();
if(ans==-1) printf("IMPOSSIBLE\n");
else printf("%d\n",ans);
}

return 0;
}
标题基于SpringBoot的在线网络学习平台研究AI更换标题第1章引言介绍基于SpringBoot的在线网络学习平台的研究背景、意义、国内外现状、论文研究方法及创新点。1.1研究背景与意义阐述在线网络学习平台的重要性及其在教育领域的应用价值。1.2国内外研究现状分析当前国内外在线网络学习平台的发展状况及趋势。1.3研究方法与创新点说明本研究采用的方法论和在研究过程中的创新之处。第2章相关理论技术概述SpringBoot框架、在线教育理论及相关技术基础。2.1SpringBoot框架概述介绍SpringBoot框架的特点、优势及其在Web应用中的作用。2.2在线教育理论阐述在线教育的基本理念、教学模式及其与传统教育的区别。2.3相关技术基础介绍开发在线网络学习平台所需的关键技术,如前端技术、数据库技术等。第3章在线网络学习平台设计详细描述基于SpringBoot的在线网络学习平台的整体设计方案。3.1平台架构设计给出平台的整体架构图,并解释各个模块的功能及相互关系。3.2功能模块设计详细介绍平台的主要功能模块,如课程管理、用户管理、在线考试等。3.3数据库设计说明平台的数据库设计方案,包括数据表结构、数据关系等。第4章平台实现与测试阐述平台的实现过程及测试方法。4.1平台实现详细介绍平台的开发环境、开发工具及实现步骤。4.2功能测试对平台的主要功能进行测试,确保功能正常且符合预期要求。4.3性能测试对平台的性能进行测试,包括响应时间、并发用户数等指标。第5章平台应用与分析分析平台在实际应用中的效果及存在的问题,并提出改进建议。5.1平台应用效果介绍平台在实际教学中的应用情况,包括用户反馈、使用情况等。5.2存在问题及原因分析分析平台在运行过程中出现的问题及其原因,如技术瓶颈、用户体验等。5.3改进建议与措施针对存在的问题提出具体的改进建议和措施,以提高平台的性能和用户满意度
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值