博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[宽度优先搜索] FZU-2150 Fire Game
阅读量:6975 次
发布时间:2019-06-27

本文共 2795 字,大约阅读时间需要 9 分钟。

Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fire all the grass. Firstly they choose two grids which are consisting of grass and set fire. As we all know, the fire can spread among the grass. If the grid (x, y) is firing at time t, the grid which is adjacent to this grid will fire at time t+1 which refers to the grid (x+1, y), (x-1, y), (x, y+1), (x, y-1). This process ends when no new grid get fire. If then all the grid which are consisting of grass is get fired, Fat brother and Maze will stand in the middle of the grid and playing a MORE special (hentai) game. (Maybe it’s the OOXX game which decrypted in the last problem, who knows.)

You can assume that the grass in the board would never burn out and the empty grid would never get fire.

Note that the two grids they choose can be the same.

Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains two integers N and M indicate the size of the board. Then goes N line, each line with M character shows the board. “#” Indicates the grass. You can assume that there is at least one grid which is consisting of grass in the board.

1 <= T <=100, 1 <= n <=10, 1 <= m <=10

Output

For each case, output the case number first, if they can play the MORE special (hentai) game (fire all the grass), output the minimal time they need to wait after they set fire, otherwise just output -1. See the sample input and output for more details.

Sample Input

43 3.#.###.#.3 3.#.#.#.#.3 3...#.#...3 3###..##.#

Sample Output

Case 1: 1Case 2: -1Case 3: 0Case 4: 2 题目描述:两个无所畏惧的小孩在草地上同时防火,问最短把草烧光用的时间。 解题思路:宽度优先搜索一下,在队列里加个时间就可以了。
#include
#include
#include
#define inf 0x7fffffffusing namespace std;class node { public: int x,y,time; }hpair;queue
q;int n,m,glnum;char map[15][15];const int dx[2][4]={
{0,0,1,-1},{-1,1,0,0}};class search { private: int i,j,step,x,y,visit[15][15],xx,yy,time; public: int bfs(int x1,int y1,int x2,int y2) { for(i=0;i<11;++i) for(j=0;j<11;++j) visit[i][j]=0; q.push((class node){x1,y1,0}); q.push((class node){x2,y2,0}); visit[x1][y1]=visit[x2][y2]=1; step=0; while(!q.empty()) { x=q.front().x;y=q.front().y;time=q.front().time;q.pop(); if(time>step) step=time; for(i=0;i<4;++i) { xx=x+dx[0][i];yy=y+dx[1][i]; if(xx>=0&&yy>=0&&xx

  

转载于:https://www.cnblogs.com/fuermowei-sw/p/6440787.html

你可能感兴趣的文章
自己设计大学排名-数据库实践
查看>>
linux环境jmeter- java环境安装配置
查看>>
STL 六大组件, 功能与运用概要
查看>>
keepalived 知识备注
查看>>
axis2学习——客户端的开发
查看>>
灾后重建 Floyd
查看>>
spring boot 项目中hanlp的配置(可增加自定义词典)
查看>>
结对项目-数独程序扩展
查看>>
系统windows版本修改
查看>>
android 多进程
查看>>
ubuntu “无法获得锁 /var/lib/dpkg/lock -open”
查看>>
大家好,我是小组成员刘俊伟
查看>>
Daily Scrum: 2012/11/2
查看>>
订单页过滤,sql写法
查看>>
H3C:下一代互联网的安全起点
查看>>
【常用】source insight常用设置及快捷键
查看>>
AD走圆弧走线
查看>>
PHP获取Linux当前目录下文件并实现下载功能
查看>>
python-操作hive
查看>>
(Spring4 json入门)Spring4+SpringMVC+页面数据发送与接收(json格式)
查看>>