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.子系统太多,每次 ...
随机推荐
- 基于unoconv的在线office预览
这几天在搞在线文档预览,网上查了几种方案, 第一种:使用google的在线预览 -> 国内被Q,pass 第二种:使用第三方的,比如:永中dcs -> 要钱,pass 第三种:先转换为pd ...
- IOS 开发入门
1.Getting Started https://developer.apple.com/library/ios/navigation/#section=Resource%20Types&t ...
- hdoj1072 Nightmare(bfs)
题目大意: 在迷宫中有一个炸弹,过六个单位时间就会爆炸,要你求一个起点到迷宫的终点的最短距离,迷宫中有时间重置器,当你走到这个格子,炸弹的爆炸时间重新置为0,迷宫中标识为墙壁的格子不能走,到达任意一个 ...
- 主机安全扫描工具-- vuls
https://vuls.io/ 一. 安装 系统管理员有责任定期去检查系统的弱点和更新软件, vuls 可以提供如下功能: 通知管理员机器有安全隐患 支持本地和远程扫描(需要有 ssh 权限) 可以 ...
- elasticsearch 5.x Delete By Query API(根据条件删除)
之前在 2.X版本里 这个Delete By Query功能被去掉了 因为官方认为会引发一些错误 如需使用 需要自己安装插件. bin/plugin install delete-by-query 需 ...
- MyBatis Generator XML 配置
使用反向生成器可以生成数据库表对应的实体类和mapper映射文件: 以下是具体介绍相应xml文件的配置: 附上一张配置的模板: <?xml version="1.0" enc ...
- 【GDOI2018模拟8】 数学竞赛 三角函数性质+记忆化搜索
数据范围:p,q≤20. 只能说我整个人傻逼了..... 我们考虑三角函数的部分性质: $sin(x)=\sqrt{ 1-cos^2(x)}$ $cos(x)=\sqrt{1-sin^2(x)}$ $ ...
- iOS 枚举讲解
枚举增强程序的可读性,用法上还是需要注意的 1.C语言的写法 enum XMPPReconnectFlags { kShouldReconnect = 1 << 0, // If set, ...
- (转)Python科学计算之Pandas详解,pythonpandas
https://www.cnblogs.com/linux-wangkun/p/5903380.html-------pandas 学习(1): pandas 数据结构之Series https:// ...
- java8新特性-入门摘要
本文是针对java8做的入门摘要笔录,详细分析可参见如下原文. 原文地址 http://www.javacodegeeks.com/2013/02/java-8-from-permgen-to-met ...