Uva 11624 - Fire! 多源宽度优先遍历

本文深入探讨了深度学习技术在音视频处理领域的应用,包括AI音视频处理、图像处理AR特效、音视频直播流媒体等。通过具体案例分析,展示了深度学习如何提升音视频质量、增强用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=543&problem=2671&mosmsg=Submission+received+with+ID+11653475

 

Problem B: Fire!


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 Specification

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.

Sample Input

2
4 4
####
#JF#
#..#
#..#
3 3
###
#J.
#.F

Output Specification

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.

Output for Sample Input

3
IMPOSSIBLE

 

/*
普通的宽度搜索题
先预处理一下map,找出每个点的着火时间,然后再次宽度搜索
如果人走到那一点的时间小于着火时间,才能入队。
*/
#include<cstdio>
#include<queue>
#include<iostream>
#include<cstring>
using namespace std;
const int M=1002;
char map[M][M];//存放地图
int newmap[M][M];//存放地图上的点的着火时间
int fang[4][2]={0,1,0,-1,1,0,-1,0};//方向数组
struct node
{
       int x;
       int y;
       int step;//记录步数
}J,F,term;
queue<node>q;
int R,C;
int main()
{
       int T,i,j,flag;
       scanf("%d",&T);
       while(T--)
       {
              while(!q.empty())q.pop();
              memset(newmap,0,sizeof(newmap));
              memset(map,0,sizeof(map));
              scanf("%d%d",&R,&C);
              for(i=1;i<=R;i++)
              {
                     for(j=1;j<=C;j++)
                     {
                            cin>>map[i][j];
                            if(map[i][j]=='J')
                            {
                                   J.x=i;
                                   J.y=j;
                                   J.step=0;
                            }
                            if(map[i][j]=='F')
                            {
                                   F.x=i;
                                   F.y=j;
                                   map[i][j]='#';
                                   q.push(F);//着火点不止一个
                            }
                     }
              }
              while(!q.empty())
              {
                     term=q.front();
                     q.pop();
                     for(i=0;i<4;i++)
                     {
                            node t;
                            t.x=term.x+fang[i][0];
                            t.y=term.y+fang[i][1];
                            if(map[t.x][t.y]==0||map[t.x][t.y]=='#'||newmap[t.x][t.y]!=0&&(newmap[t.x][t.y]<=newmap[term.x][term.y]+1))continue;
                            newmap[t.x][t.y]=newmap[term.x][term.y]+1;
                            q.push(t);
                     }
              }
              q.push(J);
              flag=0;
              while(!q.empty())
              {
                     term=q.front();
                     q.pop();
                     for(i=0;i<4;i++)
                     {
                            node t;
                            t.x=term.x+fang[i][0];
                            t.y=term.y+fang[i][1];
                            t.step=term.step+1;
                            if(map[t.x][t.y]==0){flag=1;break;}//逃出
                            if(map[t.x][t.y]=='#'||newmap[t.x][t.y]!=0&&newmap[t.x][t.y]<=t.step)continue;
                            map[t.x][t.y]='#';
                            q.push(t);
                     }
                     if(flag)break;
              }
              if(flag==1)printf("%d\n",term.step+1);
              else printf("IMPOSSIBLE\n");
       }
       return 0;
}

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值