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开发【Django】:时间处理

    时间格式化 做博客后台时,需要经常对数据库里面的时间格式(2017-02-17 02:10:44.308638)进行处理,格式化成自己想要的时间(列如年月日),下面就来记录下如何对时间进行处理 1.时 ...

  2. centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标前所有字符 Ctrl+r 搜索命 hash命令 Ctrl+左箭头/右箭头 cd命令 第三节课

    centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标 ...

  3. 用Python实现的数据结构与算法:队列

    一.概述 队列(Queue)是一种先进先出(FIFO)的线性数据结构,插入操作在队尾(rear)进行,删除操作在队首(front)进行. 二.ADT 队列ADT(抽象数据类型)一般提供以下接口: Qu ...

  4. redis error MISCONF Redis is configured to save RDB snapshots

    在操作命令incr时发生错误: (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able ...

  5. Preview all adidas NMD Singapore colorways just below

    A week ago, we've got a glimpse into adidas NMD Singapore for the future using their Tubular line. O ...

  6. cocos进阶教程(5)CC_CALLBACK_X系列的使用技巧

    CC_CALLBACK_1,CC_CALLBACK_2,CC_CALLBACK_3 这些都是std::bind的宏,数字1,2,3主要表示要占位的数量,也是将来传递参数的数量. // new call ...

  7. 利用ssh-copy-id复制公钥到多台服务器

    http://www.cnblogs.com/panchong/p/6027138.html?utm_source=itdadao&utm_medium=referral # 连接新主机时,不 ...

  8. DB开发之mysql

    1. MySQL 4.x版本及以上版本提供了全文检索支持,但是表的存储引擎类型必须为MyISAM,以下是建表SQL,注意其中显式设置了存储引擎类型 CREATE TABLE articles ( id ...

  9. 一个简单清晰的Redis操作类-php

    <?php /** * redis处理的二次封装 * */ class Redis{ private $_redis; private $_config; public function __c ...

  10. Cooperation.GTST团队第四周项目总结

    项目进展 这周我们的主要学习内容是: 1.研究学习如何导入博客详情页. 2.继续研究如何使用博客园的相关接口,导入相关jar包实现页面整体效果: 在我们使用其它APP或者上网浏览论坛.网页等时,通常都 ...