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的更多相关文章

  1. FZU 2150 Fire Game(点火游戏)

    FZU 2150 Fire Game(点火游戏) Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description - 题目描述 ...

  2. FZU 2150 Fire Game (暴力BFS)

    [题目链接]click here~~ [题目大意]: 两个熊孩子要把一个正方形上的草都给烧掉,他俩同一时候放火烧.烧第一块的时候是不花时间的.每一块着火的都能够在下一秒烧向上下左右四块#代表草地,.代 ...

  3. fzu 2150 Fire Game 【身手BFS】

    称号:fzupid=2150"> 2150 Fire Game :给出一个m*n的图,'#'表示草坪,' . '表示空地,然后能够选择在随意的两个草坪格子点火.火每 1 s会向周围四个 ...

  4. FZU 2150 Fire Game

    Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  5. FZU 2150 fire game (bfs)

    Problem 2150 Fire Game Accept: 2133    Submit: 7494Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  6. FZU 2150 Fire Game --两点同步搜索

    枚举两点,然后同步BFS,看代码吧,很容易懂的. 代码: #include <iostream> #include <cstdio> #include <cstring& ...

  7. (FZU 2150) Fire Game (bfs)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 Problem Description Fat brother and Maze are playing ...

  8. foj 2150 Fire Game(bfs暴力)

         Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M ...

  9. UVA 11624 Fire!(广度优先搜索)

    题目大意:在一个N*M的迷宫内,J代表某人(只有一个),F代表火(可能不只一个),#代表墙,火每分钟会向四周除了墙以外的地方扩散一层,问人能否在没被火烧到 之前逃出迷宫,若能逃出输出最短时间.很明显的 ...

随机推荐

  1. python 面向对象 类 __doc__

    用来打印类的描述信息 class A1(object): '''类的描述信息''' print(A1.__doc__) # 类的描述信息

  2. 002-and design-dva.js 知识导图-01JavaScript 语言,React Component

    一.概述 参看:https://github.com/dvajs/dva-knowledgemap react 或 dva 时会不会有这样的疑惑: es6 特性那么多,我需要全部学会吗? react ...

  3. python基础(基础数据类型)

    一. 引子 1. 什么是数据 x=10,10是我们要存储的数据 2. 为何数据要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同的类型的数据去表示 3.数据类型 数字 字符串 列表 元组 字 ...

  4. POJ1273:Drainage Ditches(最大流入门 EK,dinic算法)

    http://poj.org/problem?id=1273 Description Every time it rains on Farmer John's fields, a pond forms ...

  5. 网络协议TCP、Http、webservice、socket区别

    网络协议TCP.Http.webservice.socket区别 http 和 webservice 都是基于TCP/IP协议的应用层协议 webservice是基于http的soap协议传输数据 w ...

  6. 临时表单导出Excel

    function ExportExcel(url, vals) { var form = jQuery("<form action='" + url + "' me ...

  7. 在Mybatis中使用连表查询的一次实际应用

    以前在工作中很少使用多表关联查询,对连表查询的具体作用和使用场景也没有很直观的认识,通过这次在项目中的实际应用,对此有了一定的认识,特记录如下. 关联表介绍: 分别是属性表attr_info.属性值表 ...

  8. uva672

      Gangsters  N gangsters are going to a restaurant. The i-th gangster comes at the time Ti and has t ...

  9. PHP文件锁 解决并发问题

    使用多线程或是多进程时. 难免会遇到并发问题. 处理简单的并发可以使用这个办法来解决 flock($fp = fopen($lock, 'w+'), LOCK_EX | LOCK_NB)   or e ...

  10. centos6.5搭建svn

    检查已经安装版本  rpm -qa subversion如果存在旧版本,卸载yum remove subversion 安装svn yum install subversion 验证是否安装成功 sv ...