FZU2150(KB1-I)
Fire Game
Accept: 1955 Submit: 6880
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.
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
Sample Output
//2017-02-28
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue> using namespace std; char grid[][], tmp[][];
int dx[] = {, , , -};
int dy[] = {, -, , };
int book[][], answer = 0x3f3f3f3f;
struct node
{
int x, y, step;
}; void bfs(int n, int m, int x1, int y1, int x2, int y2)
{
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
tmp[i][j] = grid[i][j];
int x, y, step, ans = ;
tmp[x1][y1] = '*';
tmp[x2][y2] = '*';
queue<node> q;
node tmpnode;
tmpnode.x = x1;
tmpnode.y = y1;
tmpnode.step = ;
q.push(tmpnode);
tmpnode.x = x2;
tmpnode.y = y2;
q.push(tmpnode);
while(!q.empty())
{
x = q.front().x;
y = q.front().y;
step = q.front().step;
for(int i = ; i < ; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if(nx>=&&nx<n&&ny>=&&ny<m&&tmp[nx][ny]=='#')
{
tmpnode.x = nx;
tmpnode.y = ny;
tmpnode.step = step+;
ans = step+;
tmp[nx][ny] = '*';
q.push(tmpnode);
}
}
q.pop();
}
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
if(tmp[i][j] == '#'){
return;
}
if(ans < answer)answer = ans;
} int main()
{
int T, n, m, cnt;
cin>>T;
for(int kase = ; kase <= T; kase++)
{
cin>>n>>m;
cnt = ;
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
{
cin>>grid[i][j];
if(grid[i][j] == '#')cnt++;
}
answer = 0x3f3f3f3f;
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
{
if(grid[i][j] == '#'){
for(int i2 = i; i2 < n; i2++)
for(int j2 = ; j2 < m; j2++){
if(i==i2 && j2 <= j)continue;
if(grid[i2][j2] == '#')bfs(n, m, i, j, i2, j2);
}
}
}
if(answer == 0x3f3f3f3f)answer = -;
if(cnt==)answer=;
cout<<"Case "<<kase<<": "<<answer<<endl;
}
return ;
}
FZU2150(KB1-I)的更多相关文章
- FZU2150 Fire Game —— BFS
题目链接:https://vjudge.net/problem/FZU-2150 Problem 2150 Fire Game Accept: 2702 Submit: 9240 Time Li ...
- FZU2150 Fire Game BFS搜索
题意:就是选两个点出发,只能走草坪,看能不能走完所有的草坪 分析:由于数据范围很小,所有枚举这两个点,事先将所有的草坪点存起来,然后任选两个点走,(两个点可以是同一个点) 然后BFS就行了 注:无解的 ...
- fzu2150(bfs)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 题意:在任意两处点火,求最短时间烧光所有草堆. 分析:由于n,m比较小,将所有草堆坐标记录下来,然后暴力 ...
- [宽度优先搜索] FZU-2150 Fire Game
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns) ...
- FZU-2150.FireGame.(BFS))
本题大意:给出一个n * m的地,‘#’ 代表草, ‘.’代表陆地,每次选择这片地里的两片草,可选相等的草,选择的两片草初始状态为被燃状态,每一分钟被点燃的草会将身边的四连块点.问你需要对于给定的这片 ...
- FZU2150 :Fire Game (双起点BFS)
传送门:点我 题意:“#”是草,"."是墙,询问能不能点燃俩地方,即点燃俩“#”,把所有的草烧完,如果可以,那么输出最小需要的时间,如果不行输出-1 思路:暴力BFS,看到n和m都 ...
- FZU2150 Fire Game
题目: 两个熊孩子在n*m的平地上放火玩,#表示草,两个熊孩子分别选一个#格子点火,火可以向上向下向左向右在有草的格子蔓延,点火的地方时间为0,蔓延至下一格的时间依次加一.求烧完所有的草需要的最少时间 ...
- 手把手教你玩转nginx负载均衡(三)----配置虚拟服务器网络
引言 虽然上一篇我们成功的启动了虚拟机,也安装好了操作系统,但是这台虚拟机和主机以及其他虚拟机是没有办法连通的,我们的目标是配置多台服务器并且配置nginx反向代理,来实现负载均衡,所以不能访问内网是 ...
- 【Hello CC.NET】CC.NET 实现自动化集成
一.背景 公司的某一金融项目包含 12 个子系统,新需求一般按分支来开发,测完后合并到主干发布.开发团队需要同时维护开发环境.测试环境.模拟环境(主干).目前面临最大的两个问题: 1.子系统太多,每次 ...
随机推荐
- BS4爬取物价局房产备案价以及dataframe的操作来获取房价的信息分析
因为最近要买房子,然后对房市做了一些调研,发现套路极多.卖房子的顾问目前基本都是一派胡言能忽悠就忽悠,所以基本他们的话是不能信的.一个楼盘一次开盘基本上都是200-300套房子,数据量虽然不大,但是其 ...
- powerDesiner设计数据库的一些用法
数据库的设计主要有以下几个步骤: 1:需求分析:根据业务需求分析出满足客户的需求,从而建立相应的数据库 2:概念设计:通过数据抽象,设计系统概念模型,一般为E-R模型:(entity-relation ...
- Jmeter监控系统等资源,ServerAgent端口的本次启动端口修改
默认情况下在下载的ServerAgent下,如果服务是windows系统,则直接启动"startAgent.bat"即可,如果是Linux系统,则直接启动"./start ...
- 一对一关联查询注解@OneToOne的实例详解
表的关联查询比较复杂,应用的场景很多,本文根据自己的经验解释@OneToOne注解中的属性在项目中的应用.本打算一篇博客把增删改查写在一起,但是在改的时候遇到了一些问题,感觉挺有意思,所以写下第二篇专 ...
- OC 中的属性
自动合成 (autosynthesis) @property 语法,会做下面两件事情 自动生成存取方法 由编译器生成,编辑器里不会看到这些方法. 向类中添加适当类型的实例变量 在属性前加下划线,作为实 ...
- Python小白学习之路(十一)—【局部变量和全局变量】【关键字global】【关键字nonlocal】
写在前面: 几乎有一周没有更新学习笔记了吧 上周一周身体都不怎么舒服 然后还得写开题报告 然后还得看文献 天天就是写写写写写写~~~~~~改改改改改改~~~~~~~~~ 今天又开始学习了 希望之前的没 ...
- 下载apache-tomcat-9.0.17-windows-x64及安装以及用途
首先我们先去这个网站下载http://www.apache.org/,进入Tomcat,点击Tomcat9 下载64-bit Windows_zip 当我们下载好了之后解压,把多余的文件删除掉,也可以 ...
- Machine learning 第8周编程作业 K-means and PCA
1.findClosestCentroids function idx = findClosestCentroids(X, centroids) %FINDCLOSESTCENTROIDS compu ...
- SAS->关联分析实践
SAS系统被誉为国际上的标准软件系统,本文将详细介绍如何在SAS/EM模块中进行关联规则数据挖掘,使用的软件版本是SAS 9.1.3下的Enterprise Miner 4.3: 从SAS顶端的[解决 ...
- Spring Security构建Rest服务-1100-单机Session管理
Session失效时间: springboot配置session失效时间,只需要在application.properties里配置 #session超时时间,低于60秒按60秒server.sess ...