FZU 2150 Fire Game

fzu 2150 Fire Game 【技巧BFS】 题目: fzu 2141 Sub-Bipartite Graph (贪心) 阅读详情

Fire Game

https://vjudge.net/problem/FZU-2150
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

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

Sample Output

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

C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

const int MAXN = 10 + 5;
const int INF = 0x3f3f3f3f;
char maze[MAXN][MAXN];
bool vis[MAXN][MAXN];
int dir[4][2] = {0,1,1,0,0,-1,-1,0};
int T, n, m;
int cnt;

struct node{
	int x, y, step;
}arr[100 + 5];

bool judge(int x, int y)
{
	return x >= 0 && x < n && y >= 0 && y < m;
}

int bfs(node x, node y)
{
	queue<node> q;
	memset(vis, false, sizeof(vis));
	int tmp;
	if(x.x == y.x && x.y == y.y) tmp = cnt - 1;
	else tmp = cnt - 2;
	node now, next;
	now.x = x.x; now.y = x.y; now.step = 0;
	vis[x.x][x.y] = true;
	q.push(now);
	now.x = y.x; now.y = y.y; now.step = 0;
	vis[y.x][y.y] = true;
	q.push(now);
	while(!q.empty())
	{
		now = q.front();
		q.pop();
		for(int i = 0; i < 4; i ++)
		{
			int tx = now.x + dir[i][0];
			int ty = now.y + dir[i][1];
			if(judge(tx, ty) && !vis[tx][ty] && maze[tx][ty] == '#')
			{
				vis[tx][ty] = true;
				next.x = tx;
				next.y = ty;
				next.step = now.step + 1;
				q.push(next);
				tmp --;
			}
		}
	}
	if(tmp)
		return INF;
	return now.step;
}

int main()
{
	scanf("%d", &T);
	for(int t = 1; t <= T; t ++)
	{
		scanf("%d%d", &n, &m);
		cnt = 0;
		getchar();
		for(int i = 0; i < n; i ++)
		{
			for(int j = 0; j < m; j ++)
			{
				scanf("%c", &maze[i][j]);
				if(maze[i][j] == '#')
				{
					arr[cnt].x = i;
					arr[cnt].y = j;
					cnt ++;
				}
			}
			getchar();
		}
		int MIN = INF;
		for(int i = 0; i < cnt; i ++){
			for(int j = i; j < cnt; j ++){
				MIN = min(bfs(arr[i], arr[j]), MIN);
			}
		}
		if(MIN == INF)
			printf("Case %d: -1\n", t);
		else
			printf("Case %d: %d\n", t, MIN);
	}
	return 0;
}
在windows中安装并启动ActiveMQ5.16.2 打开ActiveMQ官网 下载ActiveMQ 点击apache-activemq-5.16.2-bin.zip进行下载 下载发后解压到c盘根目录下 在powershell中输入 ./activemq start启动 ActiveMQ服务 htpp://127.0.0.1:8161访问ActiveMQ控制台 ... 阅读详情

相关推荐

倍福TC3 PLC高速采集实战:如何用PLC-Recorder实现0.24ms级时间戳同步

本文详细介绍了倍福TC3 PLC与PLC-Recorder实现0.24ms级时间戳同步的工程实践方案。通过硬件拓扑设计、时间源选择优化、报文结构封装及同步验证方法,为工业自动化领域的高精度数据采集提供了可靠解决方案,特别适用于精密装配、激光切割等微秒级同步要求的场景。

weixin_29193359的博客 372

FZU 2150 Fire Game(点火游戏)

FZU2150FireGame(点火游戏) TimeLimit:1000mSecMemoryLimit:32768KB ProblemDescription - 题目描述   Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...

221

深入探讨 VQ-VAE:理解变分量化自动编码器

VQ-VAE代表"Variational Quantized Variational Autoencoder",是一种生成模型,通常用于处理高维数据,如图像和音频。它的设计灵感来自于变分自动编码器(VAE)和量化方法,结合了它们的优点,使得 VQ-VAE 能够生成高质量的数据,并在数据表示上引入离散性。VQ-VAE 是一种强大的生成模型,结合了变分自动编码器和量化方法的优点。它在图像和音频生成、数据压缩和生成性对抗网络等领域具有广泛的应用。

DeepViewInsight的博客 7015

fzu 2150 Fire Game

fzu 2150 Fire Game 题目大意: 给出一个m*n的图,‘#’表示草坪,‘ . ’表示空地,然后可以选择在任意的两个草坪格子点火,火每 1 s会向周围四个格子扩散,问选择那两个点使得燃烧所有的草坪花费时间最小? 具体思路: 数据范围较小,直接枚举两点选择的任意情况,分别进行bfs。取最优解就行 详细: 枚举两个人可能选的坐标情况,作为不同的初始状态 对每个初始状态进行bfs搜索,得到...

指弹键盘哼民谣 749

STM32F105双路CAN通讯无法进入接收中断问题及解决方法

STM32F105RBT6双路CAN通讯无法进入接收中断问题及解决方法

m0_62383223的博客 3442

基于Costas环的载波同步实现及Matlab仿真

其中,第一个相位环接收带噪声的待同步载波,并产生一个相位误差信号,这个误差信号再通过第二个相位环进行反馈控制,使得两个相位环的相位差保持为90度,最终输出同步载波信号。接下来,我们可以编写Costas环的仿真程序,并将上面生成的信号输入到Costas环中进行同步,最终输出同步后的载波信号。综上所述,本文介绍了如何使用Matlab实现基于Costas环的载波同步,并给出相应的源代码。上述代码中,我们初始化了Costas环的各个参数,然后通过循环迭代实现了相位估计和相位误差控制,最终输出了同步后的载波信号。

2301_78484069的博客 1048

I - Fire Game FZU - 2150(多起点BFS)

I - Fire Game FZU - 2150 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 jus...

石旭先森的博客 636

使用STM32H7点亮RGB屏幕

希望本文能对你有所帮助!RGB屏幕是一种具有红、绿、蓝三种颜色通道的显示设备,通过控制每个通道的亮度,可以显示出丰富多彩的图像和动画。要使用STM32H7控制RGB屏幕,我们需要连接适当的引脚,并编写适当的代码来控制每个颜色通道的亮度。在主循环中,我们先点亮红色通道,然后延迟一段时间,接着点亮绿色通道,再延迟一段时间,最后点亮蓝色通道,并再次延迟。需要注意的是,示例代码中的延迟循环使用了一个简单的计数器实现,但实际应用中可能需要更精确的延迟方式,例如使用定时器中断或操作系统提供的延迟函数。

QoyOle的博客 923

FZU - 2150 Fire Game

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). 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

jame_19的博客 781

华为OD技术面八股文_C++_01

汇总华为OD技术面C++方向八股文真题,并提供详细解答。

qq_45776114的博客 1884

Lammps实现甲烷与水的竞争吸附-循环不同气体分子

Lammps实现甲烷与水的竞争吸附

Rockyoung 5375

Fire Game FZU - 2150

Fire Game FZU - 2150 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 empt...

ln2037的博客 249

【AUTOSAR-COM】-5.2-“Deadline Monitoring超时监控”-2-基于IPdu实现

目录 1 在CFG中配置Deadline Monitoring超时监控 1.1 参数说明 1.2 生成代码差异 2 通过一段测试代码看Deadline Monitoring超时监控 3 使用CAN盒观察Deadline Monitoring实际测试效果 3.1 Case 1:ECU开始工作时,没有收到Frame 3.2 Case 2:ECU工作中,接收的Frame丢失、 4 小结 5 结尾 关键字: DM=Deadline Monitoring超时监控 ComFirstTime...

「汽车电子助手」的博客 1788

FZU 2150 Fire Game (BFS)

题目链接: FZU 2150 Fire Game (BFS) 题目大意: n* m 场地,#表示草坪 ,每次选两个草坪,可以向周围四块草丛扩展,扩散时间为1秒,求最少时间,扩散整个草坪. 思路: 穷举:两个点组合,之后bfs选最小 Description Fat brother and Maze are playing a kind of special (hentai) game

Dextrad_ihacker的博客 1162

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

FZU 2150 Fire Game(BFS)

题目链接:FZU 2150 Fire Game BFS。

fobdddf的专栏 2529

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

fzu 2150 Fire Game(BFS)

题目链接:fzu 2150 Fire Game 题目大意:有一块空地上有些草堆‘#’,两个小伙伴想要在这片地上玩耍,然后就要烧掉这些草堆,相邻的草堆可以相互引燃,两个人可以分别选择一块草堆点燃,问说最少需要多少时间才能烧光草堆(每人只能点一次) 解题思路:枚举两个位置同时做为起点,然后BFS,注意有一个坑点就是说草堆的个数少于2的时候,枚举不到两个起点,但是是可以烧光草堆的。

不慌不忙、不急不躁 2374

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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). At the beginning, each grid of this board is consisting of grass or just empty and then they start

樱花满地集于我心,楪舞纷飞祈愿相随 3650

【简单搜索】FZU 2150 Fire Game详解

Fire Game 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

Qiuker_jl的博客 711

【补题日记】[FZU2150]Fire Game

Pro FZU2150 Sol 之前做搜索的训练的时候这个题就A了 后来提交kuangbin的题单的时候又T了 发现 原来真的可以随缘AC(逃 然后不得不对这个程序进行优化 优化的地方在于:枚举每一个两个火的时候只需要搜索一个直角三角形就行(而不是n×m) 这样时间就少了一大半 我还试过是不是输入cin太慢 改为scanf和getchar之后时间是一样的 思路不用多说 裸的bfs 但就是细节处理不好容易T Code #include<iostream> #include<cstdio&gt

cls1277的博客 199

FZU Problem-2150 Fire Game

FZU Problem-2150 Fire Game FZU入口:http://acm.fzu.edu.cn/problem.php?pid=2150 AC代码 #include<iostream> #include<cstring> #include<cstdio> #include<queue> #include<algorithm>...

恒治学 197

FZU 2150 Fire Game(bfs--两个起点)

- FZU 2150 -

Pandora_heart的博客 309

FZU-Problem 2150 Fire Game

Problem 2150 Fire Game Accept: 392 Submit: 1502 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

有一种力量叫乐观 2371

【FZU - 2150】Fire Game(bfs)

--> Fire Game 直接写中文了 Descriptions: 两个熊孩子在n*m的平地上放火玩,#表示草,两个熊孩子分别选一个#格子点火,火可以向上向下向左向右在有草的格子蔓延,点火的地方时间为0,蔓延至下一格的时间依次加一。求烧完所有的草需要的最少时间。如不能烧完输出-1。 Input 第一行,输入一个T,表示有T组测试数据。 每组数据由一个n,m分别表示行列 1 &l...

weixin_30258027的博客 192
上一篇: HDU 2612 Find a way
下一篇: UVA 11624 Fire!
剑气扬名
博客等级 码龄7年 24粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值