UVA 11624 Fire!

2014-11-24 08:06:34 · 作者: · 浏览: 0

混合的BFS。。。

Fire!
Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

[Submit] [Go Back] [Status]

Description

Download as PDF

Problem B: Fire!

\Joe wZ http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcmtzIGluIGEgbWF6ZS4gVW5mb3J0dW5hdGVseSwgcG9ydGlvbnMgb2YgdGhlIG1hemUgaGF2ZSBjYXVnaHQgb24gZmlyZSwgYW5kIHRoZSBvd25lciBvZiB0aGUgbWF6ZSBuZWdsZWN0ZWQgdG8gY3JlYXRlIGEgZmlyZSBlc2NhcGUgcGxhbi4gSGVscCBKb2UgZXNjYXBlIHRoZSBtYXplLgo8cD5HaXZlbiBKb2U="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 squareJ, Joe's initial position in the maze, which is a passable squareF, 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

Malcolm Sharpe, Ond ej Lhoták

[Submit] [Go Back] [Status]

\

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        using namespace std; int dir_x[4]={1,-1,0,0}; int dir_y[4]={0,0,1,-1}; struct node { int x,y,f,t; }; char MP[1200][1200]; bool vis[1200][1200]; int T,n,m; bool isINSIDE(node a) { if((a.x>=0&&a.x
       
        =0&&a.y
        
          q; node Joe; memset(vis,0,sizeof(vis)); for(int i=0;i