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 ...
随机推荐
- SpringBoot入门-15(springboot配置freemarker使用YML)
https://blog.csdn.net/fengsi2009/article/details/78879924 application.yml spring: http: encoding: fo ...
- Lightoj 1054 - Efficient Pseudo Code
题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1054 题目大意: 给出n,m,问n^m的所有因子之和是多少? 解题思路: 补 ...
- rhel7安装oracle 11gR2
一.修改操作系统核心参数 在Root用户下执行以下步骤: 1)修改用户的SHELL的限制,修改/etc/security/limits.conf文件 输入命令:vi /etc/security/lim ...
- webapp开发学习---Cordova目录结构分析及一些概念
Config.xml是一个全局配置文件,用于控制cordova应用程序行为的许多方面. 这个不依赖于平台的XML文件是基于W3C的“打包Web应用程序(Widget)”规范进行安排的,并扩展到指定 ...
- Android开发学习——Volley框架
转载至: http://blog.csdn.net/guolin_blog/article/details/17482095 一些概念性的东西 大家进入上边链接理解,我贴一下 具体的实现代码: pub ...
- Java 线程是什么-渐入佳境
线程:(一)什么是线程 管哥说:程序中有多个执行流就叫多线程.多线程是多任务的一种特别的形式.好处:单个程序可以创建多个并发执行的程序来完成各自的任务.多线程能满足程序员编写高效率的程序来达到充分利用 ...
- AJPFX关于数组获取最值的思路和方法
思路分析:1.定义一个变量(max,初始值一般为数组中的第一个元素值),用来记录最大值.2.遍历数组,获取数组中的每一个元素,然后依次和max进行比较.如果当前遍历到的元素比max大,就把当前元素值给 ...
- MySQL DECIMAL数据类型
https://blog.csdn.net/zyz511919766/article/details/49335565
- 微信小程序组件解读和分析:十四、slider滑动选择器
slider滑动选择器组件说明: 滑动选择器. slider滑动选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 ...
- SQL 索引自动维护计划脚本
脚本功能: 1,查询数据库中,碎片率在5%以上(官方推荐),有一定数据里的表的索引. 2.如果碎片率在5%<碎片率<=30% 执行重新组织索引.如果在30%以上,执行重建索引 建议在执行 ...