Final Battle #1 K题 Fire game
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 <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define INF 1e9
const int maxn=*+;
char a[][];
int ta[maxn],tb[maxn],book[][],nex[][]={{,},{,},{-,},{,-}};
struct point
{
int x,y,z;
point(int x=,int y=,int z=):x(x),y(y),z(z){}
};
int m,n; int BFS(point aa,point cc)
{
queue<point>que;
que.push(aa);que.push(cc);
book[aa.x][aa.y]=;book[cc.x][cc.y]=;
int step=;
while(!que.empty())
{
point temp=que.front();
que.pop(); step=max(step,temp.z);
for(int k=;k<=;k++)
{
point pp;
pp.x=temp.x+nex[k][];
pp.y=temp.y+nex[k][];
pp.z=temp.z+;
if(pp.x<||pp.x>=m||pp.y<||pp.y>=n) continue;
if(book[pp.x][pp.y]||a[pp.x][pp.y]!='#') continue;
book[pp.x][pp.y]=;
que.push(pp);
}
}
return step;
} int main()
{
int T,ca=;
cin>>T;
while(T--)
{
cin>>m>>n;
int k=;
for(int i=;i<m;i++)
for(int j=;j<n;j++)
{
cin>>a[i][j];
if(a[i][j]=='#')
{
ta[k]=i;
tb[k++]=j;
}
}
cout<<"Case "<<ca++<<": ";
int ans=INF;
for(int i=;i<k;i++)
for(int j=i;j<k;j++)
{
memset(book,,sizeof(book));
int step=BFS(point(ta[i],tb[i],),point(ta[j],tb[j],));
int flag=;
for(int ki=;ki<m;ki++)
for(int kj=;kj<n;kj++)
if(a[ki][kj]=='#'&&book[ki][kj]==) {flag=;break;}
if(flag) {ans=min(step,ans);}
}
if(ans==INF) cout<<-<<endl;
else cout<<ans<<endl;
}
return ;
}
Final Battle #1 K题 Fire game的更多相关文章
- hdu 3986 Harry Potter and the Final Battle (最短路径)
Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/6553 ...
- hdu5080:几何+polya计数(鞍山区域赛K题)
/* 鞍山区域赛的K题..当时比赛都没来得及看(反正看了也不会) 学了polya定理之后就赶紧跑来补这个题.. 由于几何比较烂写了又丑又长的代码,还debug了很久.. 比较感动的是竟然1Y了.. * ...
- 2017Summmer_上海金马五校 F题,G题,I题,K题,J题
以下题目均自己搜 F题 A序列 一开始真的没懂题目什么意思,还以为是要连续的子串,结果发现时序列,简直智障,知道题意之后,好久没搞LIS,有点忘了,复习一波以后,直接双向LIS,处理处两个数组L和R ...
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理
2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定 ...
- 2020牛客多校第八场K题
__int128(例题:2020牛客多校第八场K题) 题意: 有n道菜,第i道菜的利润为\(a_i\),且有\(b_i\)盘.你要按照下列要求给顾客上菜. 1.每位顾客至少有一道菜 2.给顾客上菜时, ...
- 2019牛客暑期多校训练营(第四场)k题、j题
传送门 k题: 题意: 给你一串由数字构成的字符串,你从这个字符串中找子字符串使这个字符串是300的倍数 题解: 这道题和第三场的B题极其相似 首先可以把是三百的倍数分开,必须要是100和3的倍数 是 ...
- ZOJ 3879 Capture the Flag 15年浙江省赛K题
每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...
- 2016 ICPC青岛站---k题 Finding Hotels(K-D树)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5992 Problem Description There are N hotels all over ...
- 2013 南京邀请赛 K题 yet another end of the world
/** 大意:给定一组x[],y[],z[] 确定有没有两个不同的x[i], x[j] 看是否存在一个ID使得 y[i]<=ID%x[i]<=z[i] y[j]<=ID%x[j]&l ...
随机推荐
- Elasticsearch的功能、使用场景以及特点
1.Elasticsearch的功能,干什么的 2.Elasticsearch的适用场景,能在什么地方发挥作用 3.Elasticsearch的特点,跟其他类似的东西不同的地方在哪里 1.Elasti ...
- [BZOJ1453]Dface双面棋盘
Description Input Output Sample Input Sample Output HINT 线段树+并查集,暴力记录和更新一些信息,详情见代码注解. #include<cm ...
- [USACO 2011 Dec Gold] Threatening Letter【后缀】
Problem 3: Threatening Letter [J. Kuipers, 2002] FJ has had a terrible fight with his neighbor and w ...
- 题解报告:hdu 1098 Ignatius's puzzle
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1098 题目中文是这样的: 伊格内修斯在数学上很差,他遇到了一个难题,所以他别无选择,只能上诉埃迪. 这 ...
- vijos P1426兴奋剂检查 多维费用背包问题的hash
https://vijos.org/p/1426 这是个好题,容易想到用dp[i][v1][v2][v3][v4][v5]表示在前i个物品中,各种东西的容量是那个的时候,能产生的最大价值. 时间不会T ...
- 【RSA】在 ASP.NET Core中结合web前端JsEncrypt.JS使用公钥加密,.NET Core使用私钥解密;
有一个需求,前端web使用的是JsEncrypt把后端给的公钥对密码进行加密,然后后端对其进行解密: 使用的类库如下: 后端使用第三方开源类库Bouncy Castle进行RSA的加解密和生成PEM格 ...
- 短视频SDK用于旅游行业
超级简单易用的短视频SDK来自RDSDK.COM.锐动天地为开发者提供短视频编辑.视频直播.特效.录屏.编解码.视频转换,等多种解决方案,涵盖PC.iOS.Android多平台.以市场为导向,不断打磨 ...
- php自动加载函数
含义:将函数注册到SPL __autoload函数栈中.如果该栈中的函数尚未激活,则激活它们. 先看__autoload 函数 printit.class.php <?php class PRI ...
- node.js入门之一
简单的说 Node.js 就是运行在服务端的 JavaScript. Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. Node.js是一个事件驱动I/O服务端Ja ...
- RSA js加密 java解密
1. 首先你要拥有一对公钥.私钥: ``` pubKeyStr = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1gr+rIfYlaNUNLiFsK/Kn ...