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 ...
随机推荐
- js 编码详解
今天在整理 js编码解码方法时,在网上搜资料,发现一篇文章讲的不错,讲解的非常简单明了,于是乎就想转载过来,却发现无法转载到博客园,最后只能卑鄙的摘抄过来.js编码解码就是将一些对URL和数据库敏感的 ...
- [USACO 2011 Nov Gold] Cow Steeplechase【二分图】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=93 很容易发现,这是一个二分图的模型.竖直线是X集,水平线是Y集,若某条竖 ...
- Android内存堆上限Android的缺省值是16M(某些机型是24M)
转自: http://www.cnblogs.com/jacktu/archive/2010/12/30/1921475.html 大家都知道Android的上层应用是基于 Dalvik Virtua ...
- Robot Framework and Ride
Robot framework是诺西(NSN)开源的一套自动化测试工具,在通信设备自动化测试中很实用,它基于Python开发,主要模拟NMS网管配置数据到网元NODE,并读取配置看配置是否生效,ECI ...
- 463 Island Perimeter 岛屿的周长
详见:https://leetcode.com/problems/island-perimeter/description/ C++: class Solution { public: int isl ...
- 定时清除 /var/log/massage 下的信息脚本文件
定时清除 /var/log/massage 下的信息脚本 #!/bin/sh #Date: 0:07 #Author: Xiaodong #Mail: 990974238@qq.com #Puncti ...
- 关于flex布局对自己的影响
对于本图来说用了一个效果就能达到这种情况,对于我来说,今天是有进步的,具体操作就是盒子模型确实,在什么地方起来的flex就运用到该地方去,刚 开始就一直有问题,思考了半天,原来是我的控制代码出现了点错 ...
- vue-router: $router.push遇到的问题
如下图使用path时,跳转路由后的页面this.$route.params为undefined 改为name时,this.$route.params可以正确获取数据,如下图: 此为官方定义的固定搭配: ...
- .NET 原理之 ViewState
1.从MSDN中我们可以知道一个页面生命周期大约可分为为:页请求.开始.初始化.加载.验证.回发事件处理.呈现.卸载这几个阶段. HttpHandler是无状态的,aspx是高级的Http ...
- com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "FileSize"
请求阿里云的OSS接口图片信息,返回json格式的数据,通过ObjectMapper将json转为Image对象时候报错转换失败 将json转对象的代码: String jsonStr = " ...