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代表火(可能不只一个),#代表墙,火每分钟会向四周除了墙以外的地方扩散一层,问人能否在没被火烧到 之前逃出迷宫,若能逃出输出最短时间.很明显的 ...
随机推荐
- Django 的 Form组件
Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 Form类的使用: 1.定义规则: from ...
- Magento 2 初探
进入公司有一小段时间了,虽然自己之前一直从事前端工作,但是基本工作就是做一些国内电商网站的前端工作.在刚进入这家公司时,自己对 magento2 一无所知,尽管上班前看过老大发给我的一些文档资料,但是 ...
- uchome 常用函数示例
一.inserttable //添加数据 //前3个参数 $tablename插入的表名称 $insertsqlarr数据数组 $returnid是否返回插入ID function inserttab ...
- python 面向对象 公有属性
公有属性定义 公有属性也叫作类变量 静态字段 class role(): # 传参数 # 公有属性都在这里定义 # 在类里直接定义的属性即是公有属性 nationality = 'JP' def ...
- web项目读取classpath路径下面的文件
首先分两大类按web容器分类 一种是普通的web项目,像用Tomcat容器,特点是压缩包随着容器的启动会解压缩成一个文件夹,项目访问的时候,实际是去访问文件夹,而不是jar或者war包. 这种的无论你 ...
- 史上最全的MonkeyRunner自动化测试从入门到精通(1)
原文地址https://zhuanlan.zhihu.com/p/26043620 MonkeyRunner使用 #-*- coding:utf-8 –*- from com.android.monk ...
- SpringData修改和删除操作
SpringData的查询我们已经学完了,我们现在就研究一下SpringData的修改和删除. @Modifying 注解和事务 @Query 与 @Modifying 这两个 annotation一 ...
- poj2954 Triangle
地址:http://poj.org/problem?id=2954 题目: Triangle Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- TED #07# How to inspire every child to be a lifelong reader
Alvin Irby: How to inspire every child to be a lifelong reader Prepare elementarykitchen tableforced ...
- Ubuntu 16.04+1080Ti机器学习基本环境配置【转】
本文转载自:https://blog.csdn.net/MahoneSun/article/details/80808930 一.设置网络 机器有两张网卡,将当前正在使用的“有线连接1”配置为以下的设 ...