FZU 2150 Fire Game(点火游戏)

Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description - 题目描述

  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.

胖哥和Maze 正用一块N*M的板子(N行,M列)玩一种特别(hentai)的游戏。开始时,板上的每个格子里要么是杂草丛生,要么空空如也。他们正准备烧掉所有的杂草。首先他们选了两个草格子点火。众所周知,火势可以沿着杂草传播。如果格子(x, y)在时间t被点燃,火势则会在t+1的时候蔓延到相邻格子(x+, y), (x-, y), (x, y+), (x, y-)上。这个过程会持续到火势无法传递。如果所有草格子都被点燃,胖哥和Maze 会站在格子中间并玩一个更加特别(hentai)的游戏。(或许是在最后一题后被解码的OOXX游戏,天知道。)
你可以认为格子无法烧坏,并且空格子无法燃烧。
注意,被选择的两个格子可以是同一个。

CN

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

数据的第一行为一个整数T,表示测试用例的数量。
随后T行,每个用例有两个表示板子大小的整数N和M。随后N行,每行M个表示格子的字符。“#”表示杂草。你可以任务板上至少有一个草格子。
<= T <=, <= n <=, <= m <=

CN

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.

对于每个测试用例,先输出用例编号,如果他们可以玩更特别(hentai)的游戏(点燃所有杂草),输出他们点火后需要等待的最短时间,否则输出-。详情参照输入输出样例。

CN

Sample Input - 输入样例

4
3 3
.#.
###
.#.
3 3
.#.
#.#
.#.
3 3
...
#.#
...
3 3
###
..#
#.#

Sample Output - 输出样例

Case 1: 1
Case 2: -1
Case 3: 0
Case 4: 2

题解

  数据不大,直接无脑BFS,就是多了一个起点。

  先判断杂草区域是否多余两片(只能点2次火),再进行BFS,比较每次的时间即可。

代码 C++

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define INF 0x7F7F7F7F
#define MX 15
struct Point{
int y, x;
}pit[MX*MX], now, nxt;
char map[MX][MX];
int data[MX][MX], fx[] = { , , -, , , -, , };
std::queue<Point> q;
int main(){
int t, it, n, m, opt, tmpOPT, i, j, k, iP, siz, sum, tmp;
for (it = scanf("%d", &t); it <= t; ++it){
opt = INF; iP = siz = sum = ;
memset(map, '.', sizeof map);
scanf("%d%d ", &n, &m);
for (i = ; i <= n; ++i) gets(&map[i][]); for (i = ; i <= n; ++i) for (j = ; j <= m; ++j){
if (map[i][j] != '#') continue;
now.y = i; now.x = j;
q.push(now); ++siz; map[now.y][now.x] = '@';
while (!q.empty()){
now = q.front(); q.pop();
pit[iP++] = now; ++sum;
for (k = ; k < ; k += ){
nxt.y = now.y + fx[k]; nxt.x = now.x + fx[k + ];
if (map[nxt.y][nxt.x] == '#'){ q.push(nxt); map[nxt.y][nxt.x] = '@'; }
}
}
}
if (siz>){ printf("Case %d: -1\n", it); continue; }
for (i = ; i < iP; ++i) for (j = i; j < iP; ++j){
memset(data, 0x7F, sizeof data);
data[pit[i].y][pit[i].x] = data[pit[j].y][pit[j].x] = ;
q.push(pit[i]); q.push(pit[j]); tmpOPT = ;
siz = i == j ? : ;
while (!q.empty()){
now = q.front(); q.pop();
tmpOPT = data[now.y][now.x]; tmp = tmpOPT + ;
for (k = ; k < ; k += ){
nxt.y = now.y + fx[k]; nxt.x = now.x + fx[k + ];
if (map[nxt.y][nxt.x] == '@' && data[nxt.y][nxt.x] == INF){
q.push(nxt); data[nxt.y][nxt.x] = tmp; ++siz;
}
}
}
if (siz == sum) opt = std::min(opt, tmpOPT);
}
printf("Case %d: %d\n", it, opt);
}
return ;
}

FZU 2150 Fire Game(点火游戏)的更多相关文章

  1. FZU 2150 Fire Game

    Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  2. fzu 2150 Fire Game 【身手BFS】

    称号:fzupid=2150"> 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个 ...

  3. FZU 2150 fire game (bfs)

    Problem 2150 Fire Game Accept: 2133    Submit: 7494Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  4. FZU 2150 Fire Game (暴力BFS)

    [题目链接]click here~~ [题目大意]: 两个熊孩子要把一个正方形上的草都给烧掉,他俩同一时候放火烧.烧第一块的时候是不花时间的.每一块着火的都能够在下一秒烧向上下左右四块#代表草地,.代 ...

  5. (FZU 2150) Fire Game (bfs)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 Problem Description Fat brother and Maze are playing ...

  6. FZU 2150 Fire Game (bfs+dfs)

    Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...

  7. FZU 2150 Fire Game 广度优先搜索,暴力 难度:0

    http://acm.fzu.edu.cn/problem.php?pid=2150 注意这道题可以任选两个点作为起点,但是时间仍足以穷举两个点的所有可能 #include <cstdio> ...

  8. FZU 2150 Fire Game 【两点BFS】

    Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns) ...

  9. FZU 2150 Fire Game (高姿势bfs--两个起点)(路径不重叠:一个队列同时跑)

    Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows ...

随机推荐

  1. 移动端点击返回时强制页面刷新解决办法(pageshow)

    在做移动端项目的时候经常遇到这样一个功能比如: 返回后页面不刷新,一些失效的信息依然显示在页面上.这个问题在iphone手机上会出现,在Android手机上返回时会自动刷新(由于手机机器种类不多,无法 ...

  2. centos下搭建Jenkins持续集成环境(安装jenkins)

    1.安装JDK yum install -y java 2.安装jenkins 添加Jenkins库到yum库,Jenkins将从这里下载安装. 1 wget -O /etc/yum.repos.d/ ...

  3. kali linux 压缩文件解压缩命令(包含7z)

    tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ——————————————— .gz 解压1 ...

  4. 给web项目整合富文本编辑器

    给jsp页面整合富文本编辑器下载——删除多余的组件——加入到项目中——参照案例来完成整合步骤:1. 解压zip文件,将所有文件复制到Tomcat的webapps/kindeditor目录下. 2. 将 ...

  5. Eloquent JavaScript #05# higher-order functions

    索引 Notes 高阶函数 forEach filter map reduce some findIndex 重写课本示例代码 Excercises Flattening Your own loop ...

  6. jsoi2018 R1R2

    Jsoi2018 R1: D1:T1:签到题,状压dp,(思考:讲题人说可以卡一卡空间,怎么做?) T2:50pts:贪心,因为无重复 100pts:线段树合并? T3:25pts 树形dp D1:T ...

  7. Linux网络管理(一):网卡驱动与Linux内核

    下图简单描述了网卡驱动与Linux内核之间的联系: 关于上图的一些说明: 系统初始化: 1. 协议模块调用 dev_add_pack() 来注册协议处理函数到链表 &ptype_base: 2 ...

  8. nginx 启动 + uwsgi + django

    https://www.cnblogs.com/chenice/p/6921727.html https://blog.csdn.net/Aaroun/article/details/78218131

  9. 禁止单个IP或ip段访问

    //IP禁止判断接口,返回true则为找到 function checkIp($ip, $ipbanned) { $ipbannedFlag = false; if (!empty($ipbanned ...

  10. 安装虚拟环境virtualenvwrapper和django

    以下操作在windows平台进行 1.安装虚拟环境virtualenvwrapper 首先需要安装python管理工具pip,安装完python3.7之后自带了pip,可通过where pip查看管理 ...