FZU 2150 Fire Game 广度优先搜索,暴力 难度:0
http://acm.fzu.edu.cn/problem.php?pid=2150
注意这道题可以任选两个点作为起点,但是时间仍足以穷举两个点的所有可能
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=11;
const int inf=0x3fffffff;
char maz[maxn][maxn];
int dp[maxn][maxn];
int n,m,mxn,num; queue<int> que;
const int dx[8]={0,0,1,-1,1,1,-1,-1};
const int dy[8]={1,-1,0,0,1,-1,1,-1};
struct pnt {
int x,y;
pnt(){x=y=0;}
pnt(int tx,int ty){x=tx,y=ty;}
};
bool in(int x,int y){
return x>=0&&x<n&&y>=0&&y<m;
}
void bfs(pnt s,pnt s2){
while(!que.empty())que.pop();
int tnum=0;
int tmxn=0;
dp[s.x][s.y]=0;
tnum++;
que.push(s.x*maxn+s.y);
if(s2.x!=s.x||s2.y!=s.y){
dp[s2.x][s2.y]=0;
tnum++;
que.push(s2.x*maxn+s2.y);
}
while(!que.empty()){
int x=que.front()/maxn,y=que.front()%maxn;que.pop();
tmxn=max(tmxn,dp[x][y]);
for(int i=0;i<4;i++){
int tx=x+dx[i],ty=y+dy[i];
if(in(tx,ty)&&maz[tx][ty]=='#'&&dp[tx][ty]>dp[x][y]+1){
dp[tx][ty]=dp[x][y]+1;
tnum++;
que.push(tx*maxn+ty);
}
}
}
if(tnum==num)mxn=min(mxn,tmxn);
}
void init(){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
dp[i][j]=inf;
}
} }
pnt heap[maxn*maxn];int hlen;
int main(){
int T;
scanf("%d",&T);
for(int ti=1;scanf("%d%d",&n,&m)==2&&ti<=T;ti++){
for(int i=0;i<n;i++){
scanf("%s",maz[i]);
}
num=0;mxn=inf;hlen=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(maz[i][j]=='#'){
num++;
heap[hlen++]=pnt(i,j);
}
}
}
for(int i=0;i<hlen;i++){
for(int j=i;j<hlen;j++){
init();
bfs(heap[i],heap[j]);
}
} printf("Case %d: %d\n",ti,mxn==inf?-1:mxn);
}
return 0;
}
FZU 2150 Fire Game 广度优先搜索,暴力 难度:0的更多相关文章
- 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~~ [题目大意]: 两个熊孩子要把一个正方形上的草都给烧掉,他俩同一时候放火烧.烧第一块的时候是不花时间的.每一块着火的都能够在下一秒烧向上下左右四块#代表草地,.代 ...
- fzu 2150 Fire Game 【身手BFS】
称号:fzupid=2150"> 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个 ...
- FZU 2150 Fire Game
Fire Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- FZU 2150 fire game (bfs)
Problem 2150 Fire Game Accept: 2133 Submit: 7494Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- FZU 2150 Fire Game --两点同步搜索
枚举两点,然后同步BFS,看代码吧,很容易懂的. 代码: #include <iostream> #include <cstdio> #include <cstring& ...
- (FZU 2150) Fire Game (bfs)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 Problem Description Fat brother and Maze are playing ...
- foj 2150 Fire Game(bfs暴力)
Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M ...
- UVA 11624 Fire!(广度优先搜索)
题目大意:在一个N*M的迷宫内,J代表某人(只有一个),F代表火(可能不只一个),#代表墙,火每分钟会向四周除了墙以外的地方扩散一层,问人能否在没被火烧到 之前逃出迷宫,若能逃出输出最短时间.很明显的 ...
随机推荐
- 转!!mysql 字段 is not null 和 字段 !=null
今天在查询数据时,查到包含一条某个时间startTime(该字段默认为null ) 为null的记录,想把它过滤,加了 startTime != null 的条件,结果记录都没了,应该用条件 is ...
- Linux知识总汇
Linux相关教程 Linux的安装以及基础配置 Linux上安装Python3 Linux上安装pip以及setuptools Linux上安装MySQL Linux上安装Django Linux上 ...
- IP层网络安全协议(IPSec)技术原理图解——转载图片
- (2.8)Mysql之SQL基础——索引的分类与使用
(2.8)Mysql之SQL基础——索引的分类与使用 关键字:mysql索引,mysql增加索引,mysql修改索引,mysql删除索引 按逻辑分类: 1.主键索引(聚集索引)(也是唯一索引,不允许有 ...
- PAT 1100 Mars Numbers[难]
1100 Mars Numbers (20 分) People on Mars count their numbers with base 13: Zero on Earth is called &q ...
- ng-深度学习-课程笔记-3: Python和向量化(Week2)
1 向量化( Vectorization ) 在逻辑回归中,以计算z为例,$ z = w^{T}+b $,你可以用for循环来实现. 但是在python中z可以调用numpy的方法,直接一句$z = ...
- Java 泛型通配符上限和通配符下限
①为什么要使用泛型通配符 请参考这篇随笔的下半部分 https://www.cnblogs.com/baxianhua/p/9194369.html ②通配符上限和通配符下限的简单解释 <? ...
- Linux的crontab
如果要让unix系统重复,定期做一件事,我们就会用到crontab. 实质上真正去执行每一个重复任务的是cron,cron是的unix家族的一个后台常驻程序,cron是由cron文件来驱动的,cron ...
- net.sf.json和 com.fasterxml.jackson中对象转json的区别
近期做项目的时候,发现使用net.sf.json包中的JSONObject或JSONArray将对象转为json数据结构存在一个坑.当对String类型的属性赋值为null情况下,转为json结构为& ...
- Markdown中的表格
参考:在简书上用Markdown写表格 | Tables | Are | Cool | | ------------- |:-------------:| -----:| | col 3 is | r ...