(广搜)Fire Game -- FZU -- 2150
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82828#problem/I
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
using namespace std; #define INF 0x3f3f3f3f
#define N 20 struct node
{
int x, y, step;
}a[N*N]; int n, m, t;
char G[N][N];
int f[N][N];
int dir[][] = {{-,},{,-},{,},{,}}; int BFS(node s1, node s2)
{
node p, q; queue<node>Q;
Q.push(s1);
Q.push(s2); t = ;
f[s1.x][s1.y] = ;
f[s2.x][s2.y] = ; while(Q.size())
{
p = Q.front(), Q.pop(); for(int i=; i<; i++)
{
q.x = p.x + dir[i][];
q.y = p.y + dir[i][]; if(q.x>= && q.x<n && q.y>= && q.y<m && G[q.x][q.y]=='#' && !f[q.x][q.y])
{
f[q.x][q.y] = ;
q.step = p.step + ;
t = max(t, q.step);
Q.push(q);
}
}
} return t;
} int Judge()
{
int i, j; for(i=; i<n; i++)
for(j=; j<m; j++)
{
if(G[i][j]=='#' && !f[i][j])
return ;
}
return ;
} int main()
{
int T, iCase=;
scanf("%d", &T);
while(T--)
{
int i, j, k=;
scanf("%d%d", &n, &m); memset(G, , sizeof(G));
for(i=; i<n; i++)
{
scanf("%s", G[i]);
for(j=; j<m; j++)
{
if(G[i][j]=='#')
{
a[k].x=i, a[k].y=j, a[k].step=;
k++;
}
}
} int ans=INF, Step;
for(i=; i<k; i++)
for(j=i; j<k; j++)
{
memset(f, , sizeof(f));
Step = BFS(a[i], a[j]);
if(Step<ans && Judge())
ans = Step;
} printf("Case %d: ", iCase++);
if(ans==INF)
printf("-1\n");
else
printf("%d\n", ans);
}
return ;
}
(广搜)Fire Game -- FZU -- 2150的更多相关文章
- Fire Game FZU - 2150 (bfs)
Problem 2150 Fire Game Accept: 3772 Submit: 12868Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- kuangbin专题 专题一 简单搜索 Fire Game FZU - 2150
题目链接:https://vjudge.net/problem/FZU-2150 题意:’ . '代表火无法烧着的地方,‘ # ’表示草,火可以烧着.选择任意两个‘ # ’(可以两个都选同一个 ‘ # ...
- ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪
FZU 2150 Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- FZU 2150 Fire Game
Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- FZU 2150 Fire Game(点火游戏)
FZU 2150 Fire Game(点火游戏) Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description - 题目描述 ...
- FZU 2150 Fire Game (暴力BFS)
[题目链接]click here~~ [题目大意]: 两个熊孩子要把一个正方形上的草都给烧掉,他俩同一时候放火烧.烧第一块的时候是不花时间的.每一块着火的都能够在下一秒烧向上下左右四块#代表草地,.代 ...
- HDU--杭电--1195--Open the Lock--深搜--都用双向广搜,弱爆了,看题了没?语文没过关吧?暴力深搜难道我会害羞?
这个题我看了,都是推荐的神马双向广搜,难道这个深搜你们都木有发现?还是特意留个机会给我装逼? Open the Lock Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5652(二分+广搜)
题目链接:http://acm.hust.edu.cn/vjudge/contest/128683#problem/E 题目大意:给定一只含有0和1的地图,0代表可以走的格子,1代表不能走的格 子.之 ...
- nyoj 613 免费馅饼 广搜
免费馅饼 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy ...
随机推荐
- JavaScript 练习题
练习题 1. 使用for循环输出1到50的值,要求每次循环只能输出一个值,每输出十个换一行. 2 日历生成器: 要求 用户输入,这个月有多少天,本月1号是星期几,自动生成日历 3. 表格生成器 4. ...
- spring+mybatis+mina+logback框架搭建
第一次接触spring,之前从来没有学过spring,所以算是赶鸭子上架,花了差不多一个星期来搭建,中间遇到各种各样的问题,一度觉得这个框架搭建非常麻烦,没有一点技术含量,纯粹就是配置,很低级!但随着 ...
- Bowtie2的安装与使用
Bowtie2的安装与使用 2017-06-15 18:58:52 342 0 0 Bowtie2用来快速比对短reads(50-100bp)与参考基因组,与常规的比对软件不 ...
- HapMap
HapMap五周年回顾 2011-01-12 | 作者: [关闭] 作者简介:曾长青,中国科学院北京基因组所研究员,博士生导师.CUSBEA奖学金.百人计划.杰出青年基金.首批新世纪百千万人才工程国家 ...
- 20172306《java程序设计与数据结构》第六周学习总结
20172306<Java程序设计>第六周学习总结 教材学习内容总结 第八章关键学习了数组的相关内容.我觉得主要分一下几点: 1.索引是从0开始,要区分好索引值和个数值.0的索引处是第一个 ...
- 判断某个字符串里面是否包含caoyang 这个字符串?
$string = 'Lorem ipsum dolor sit amet'; $preg = '/caoyang/'; $status = preg_match($preg, $string,$ma ...
- sleep()方法和yield()方法有什么区别?
两者都是Thread类的静态方法,定义如下 public static void sleep(long millis) throws InterruptedException public stati ...
- ssrf绕过总结
前言 昨天忘了在公众号还是微博上看到的了,看到一个SSRF绕过的技巧,使用的是 ⓔⓧⓐⓜⓟⓛⓔ.ⓒⓞⓜ 绕过的,自己也没遇到过.然后想想自己对SSRF绕过还是停留在之前的了解,也没学习过新的绕过方法, ...
- NETSHARP的JAVA开发环境配置
一:JAVA配置 1. netsharp使用java1.8/1.7版本,本文使用1.8版本 2.jdk下载地址:http://www.oracle.com/technetwork/java/javas ...
- 使用Python完成排序(冒泡、选择、插入法)
class Sort(object): @staticmethod def bubble_sort(ls): lenth = len(ls) if lenth == 0: return [] whil ...