题目大意:
这是一个放火逃生的游戏,就是给出来一个迷宫,迷宫里面有人‘J’和火焰‘F’当然这些火焰可能不止一处,然后问这个人最快从迷宫里面逃出来需要多久
////////////////////////////////////////////////////////////
最简单明了的办法就是写两个BFS,这样很容易理解,好吧,那就这么办吧,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
试一下吧。
第一次提交wa,只想到了火焰可能有多处,实际上还有可能没有火焰......
#include<queue>
#include<stdio.h>
#include<string.h>
using namespace std; #define maxn 1005
const int oo = 0xfffffff; struct node{int x, y;};
node JoeSite, FireSite[maxn*maxn];//因为火可能不止一处,所以开一个数组保存所有的火焰的位置
char G[maxn][maxn];
int vJoe[maxn][maxn], vFire[maxn][maxn];
int dir[][] = { {,},{,-},{,},{-,} };
int M, N, nFire; void BfsFire()
{
    node s, q;
    queue<node> Q;
    int i;     for(i=; i<nFire; i++)
    {
        Q.push(FireSite[i]);
        vFire[ FireSite[i].x ][ FireSite[i].y ] = ;
    }     while(Q.size())
    {
        s = Q.front();Q.pop();         for(i=; i<; i++)
        {
            q = s;
            q.x += dir[i][];
            q.y += dir[i][];             if(q.x>=&&q.x<M && q.y>=&&q.y<N && G[q.x][q.y]!='#' && vFire[q.x][q.y]==oo)
            {
                vFire[q.x][q.y] = vFire[s.x][s.y] + ;
                Q.push(q);
            }
        }
    }
} int IsBorder(int x, int y)//判断是否是边界并且是否比火焰先到达
{
    if( (x== || x==M- || y== || y==N-) && vJoe[x][y] < vFire[x][y] )
        return ;
    return ;
} int  BfsJoe()
{
    queue<node> Q;
    node s, q;
    int i;     vJoe[JoeSite.x][JoeSite.y] = ;
    Q.push(JoeSite);     while(Q.size())
    {
        s = Q.front();Q.pop();         if(IsBorder(s.x, s.y) == )
            return vJoe[s.x][s.y];         for(i=; i<; i++)
        {
            q = s;
            q.x += dir[i][];
            q.y += dir[i][];             if(q.x>=&&q.x<M && q.y>=&&q.y<N && G[q.x][q.y]!='#' && vJoe[q.x][q.y]==)
            {
                vJoe[q.x][q.y] = vJoe[s.x][s.y] + ;
                Q.push(q);
            }
        }
    }     return -;
} int  main()
{
    int T;     scanf("%d", &T);     while(T--)
    {
        int i, j, ans;         scanf("%d%d", &M, &N);         nFire = ;         for(i=; i<M; i++)
        {
            scanf("%s", G[i]);
            for(j=; j<N; j++)
            {
                vJoe[i][j] = ;
                vFire[i][j] = oo;                 if(G[i][j] == 'J')
                    JoeSite.x = i, JoeSite.y = j;
                if(G[i][j] == 'F')
                {
                    FireSite[nFire].x = i;
                    FireSite[nFire++].y = j;
                }
            }
        }         BfsFire();
        ans = BfsJoe();         if(ans == -)
            printf("IMPOSSIBLE\n");
        else
            printf("%d\n", ans);
    }     return ;

}

J - Fire!的更多相关文章

  1. UVA - 11624 J - Fire! (BFS)

    题目传送门 J - Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the ...

  2. J - Fire!---UVA 11624

    题目链接 题意:J代表Joe的位置,F代表火的起点,下一刻火将会向四周扩散,求Joe逃离的最短时间,如果不能逃离输出IMPOSSIBLE; 注意火的起点可能不止一处 可以用两次bfs分别求出人到达某个 ...

  3. Fire逃生

    Description: You are trapped in a building consisting of open spaces and walls. Some places are on f ...

  4. Fire! -两次dfs

    题目描述: Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of ...

  5. Fire! 又是图 bfs

    Joe works in a maze.  Unfortunately, portions of the maze havecaught on  re, and the owner of the ma ...

  6. UVA - 11624 Fire! 【BFS】

    题意 有一个人 有一些火 人 在每一秒 可以向 上下左右的空地走 火每秒 也会向 上下左右的空地 蔓延 求 人能不能跑出来 如果能 求最小时间 思路 有一个 坑点 火是 可能有 多处 的 样例中 只有 ...

  7. 【UVA - 11624】Fire!

    -->Fire! 直接上中文 Descriptions: 乔在迷宫中工作.不幸的是,迷宫的一部分着火了,迷宫的主人没有制定火灾的逃跑计划.请帮助乔逃离迷宫.根据乔在迷宫中的位置以及迷宫的哪个方块 ...

  8. kuangbin专题 专题一 简单搜索 Fire! UVA - 11624

    题目链接:https://vjudge.net/problem/UVA-11624 题意:一个迷宫,可能有一个或者多个地方着火了,每过1个时间消耗,火会向四周蔓延,问Joe能不能逃出迷宫,只要走出迷宫 ...

  9. UVA11624Fire!(BFS)

    题目链接 题意:帮助joe走出一个大火蔓延的迷宫,其中joe每分钟可往上下左右四个方向之一走,所有着火的格子都会蔓延(空格与着火格有公共边,下一分钟这个空格也会着火).迷宫中有一些障碍格,joe和火都 ...

随机推荐

  1. 函数对象的prototype总结

    通过看 http://www.cnblogs.com/mindsbook/archive/2009/09/19/javascriptYouMustKnowPrototype.html 该文章和对代码的 ...

  2. left join 和 left outer join 有什么区别?

    left join 是left outer join的简写,left join默认是outer属性的.outer join则会返回每个满足第一个(顶端)输入与第二个(底端)输入的联接的行.它还返回任何 ...

  3. C#和asp.net中链接数据库中 参数的几种传递方法

    #region 参数传递方法第一种 //参数设置方法(第一种) //SqlParameter sp = new SqlParameter("@Name", str_Name); / ...

  4. iOS7初体验(2)——单元测试

    在Xcode 4.6及以前的版本,一直觉得单元测试这部分功能做得很鸡肋,用起来感觉很别扭.这一次Xcode 5.0默认就引入了单元测试,赶快来看看看相比以前的版本有什么提升吧!~_~ 1.     首 ...

  5. iOS 使用 FFmpeg

    iOS 使用 FFmpeg 字数486 阅读288 评论7 喜欢5 集成 下载FFmpeg For iOS编译脚本: 打开 terminal 执行sh build-ffmpeg.sh: 步骤2执行完成 ...

  6. Xcode 7真机测试详解

    1.准备 注意:一定要让你的真机设备的系统版本和app的系统版本想对应,如果不对应就会出现一个很常见的问题:could not find developer disk image 首先,准备好下面的设 ...

  7. WHU 1579 Big data (DP)

    题意: f[0]=0,f[i]=f[i-1]+a or b. 求满足L<=∑f[n]<=R的序列的种数 n<100.  |a|,|b|<=10000.  |L|,|R|< ...

  8. PAT - 基础 - 龟兔赛跑

    题目: 乌龟与兔子进行赛跑,跑场是一个矩型跑道,跑道边可以随地进行休息.乌龟每分钟可以前进3米,兔子每分钟前进9米:兔子嫌乌龟跑得慢,觉得肯定能跑赢乌龟,于是,每跑10分钟回头看一下乌龟,若发现自己超 ...

  9. html良好结构-之豆瓣风格

    良好HTML结构 1 结构层次 unit> hd+ unit-wrap>section>item2 语议化的结构 html5 html 语议 ck-box-unit ck-hd-wr ...

  10. js基础 - 兼容代码

    js基础 - 兼容代码 . scrollTop . chrome document.body.scrollTop . IE && firefox document.documentEl ...