题意,10*10的地图,有若干块草地“#”,草地可以点燃,并在一秒后点燃相邻的草地。有墙壁‘·‘阻挡。初始可以从任意两点点火。问烧完最短的时间。若烧不完输出-1.

题解:由于100的数据量,直接暴力。枚举两个起点,推入队列,然后bfs。烧完就返回深度,更新一个min值。

坑:(帮同学照bug)

return t.step+1;bfs后没有算上最后一步

ac代码

#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
char map[][];
int vis[][];
int T, n, m, ans, num;
struct Node {
int i, j, step;
Node(int i = , int j = , int step = ) :i(i), j(j), step(step) {}
};
int dir[][] = { { , },{ -, },{ , },{ ,- } };
bool check(int i, int j) {
if (i< || i >= n || j< || j >= m || vis[i][j] || map[i][j] == '.') return true;
return false;
}
int bfs(int i, int j, int x, int y) {
queue<Node>q;
q.push(Node(i, j, )); q.push(Node(x, y, ));
vis[i][j] = ; vis[x][y] = ;
int cnt;
if (i == x&&j == y) cnt = ;
else cnt = ;
while (!q.empty()) {
Node t = q.front();
q.pop();
for (int k = ; k<; k++) {
int di = t.i + dir[k][];
int dj = t.j + dir[k][];
if (check(di, dj)) continue;
q.push(Node(di, dj, t.step + ));
vis[di][dj] = ;
cnt++;
}
if (cnt >= num) {
//cout << i << ' ' << j << ' ' << x << ' ' << y <<' '<<t.step<< endl;
return t.step+; }
}
return -;
}
int main() {
scanf("%d", &T);
for (int t = ; t <= T; t++) {
ans = (int)1e9; num = ;
scanf("%d%d", &n, &m);
for (int i = ; i<n; i++) {
scanf("%s", map[i]);
for (int j = ; j<m; j++) if (map[i][j] == '#') num++;
}
if (num <= ) { printf("Case %d: %d\n", t, ); continue; }
for (int i = ; i<n; i++) {
for (int j = ; j<m; j++) {
if (map[i][j] != '#') continue;
for (int x = ; x<n; x++) {
for (int y = ; y<m; y++) {
if (map[x][y] != '#') continue;
memset(vis, , sizeof(vis));
int tmp = bfs(i, j, x, y);
if (tmp>) ans = min(ans, tmp);
}
}
}
}
if (ans == (int)1e9) ans = -;
printf("Case %d: %d\n", t, ans);
}
}

FZU - 2150 Fire Game bfs+双起点枚举的更多相关文章

  1. (FZU 2150) Fire Game (bfs)

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

  2. FZU 2150 Fire Game (bfs+dfs)

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

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

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

  4. fzu 2150 Fire Game 【身手BFS】

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

  5. FZU 2150 Fire Game (暴力BFS)

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

  6. FZU 2150 fire game (bfs)

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

  7. FZU 2150 Fire Game

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

  8. (简单) FZU 2150 Fire Game ,Floyd。

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

  9. FZU 2150 Fire Game(双起点)【BFS】

    <题目链接> 题目大意: 两个熊孩子在n*m的平地上放火玩,#表示草,两个熊孩子分别选一个#格子点火,火可以向上向下向左向右在有草的格子蔓延,点火的地方时间为0,蔓延至下一格的时间依次加一 ...

随机推荐

  1. grid网格的流动一

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. MyEclipse weblogic Deploy Location项目名称不正确解决方案

    MyEclipse weblogic Deploy Location项目名称不正确 MyEclipse部署weblogic 项目,名称错误,是别的项目名称 ====================== ...

  3. 【代码审计】iZhanCMS_v2.1 前台IndexController.php页面存在SQL注入 漏洞分析

      0x00 环境准备 iZhanCMS官网:http://www.izhancms.com 网站源码版本:爱站CMS(zend6.0) V2.1 程序源码下载:http://www.izhancms ...

  4. 基于端口的弱口令检测工具--iscan

    亲手打造了一款弱口令检测工具,用Python编写,主要可以用于内网渗透.弱口令检测等方面,目前集成了常见端口服务,包含 系统弱口令:ftp.ssh.telnet.ipc$ 数据库弱口令:mssql.m ...

  5. Hadoop集群三种作业调度算法介绍

    Hadoop集群中有三种作业调度算法,分别为FIFO,公平调度算法和计算能力调度算法 先来先服务(FIFO) Hadoop中默认的调度器FIFO,它先按照作业的优先级高低,再按照到达时间的先后选择被执 ...

  6. Google TensorFlow 机器学习框架介绍和使用

    TensorFlow是什么? TensorFlow是Google开源的第二代用于数字计算(numerical computation)的软件库.它是基于数据流图的处理框架,图中的节点表示数学运算(ma ...

  7. cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration的解决

    导入了一个工程,编译什么的都还好,但是报了一个XML的错误. cvc-complex-type.2.4.c: The matching wildcard is strict, but no decla ...

  8. 【sql进阶】查询每天、每个设备的第一条数据

    需求如下 每个设备(不同DeviceID).每天会向数据库插入多条数据,求每天.每个设备插入的第一条数据. 下面SQL中的 ShareRecommendID 类比不同设备的DeviceID. ROW_ ...

  9. vuex - 简单使用步骤梳理,轻松掌握、附源码

    -----------------------往期----------------------------- vuex - 学习日记 vuex - 辅助函数学习 vuex - 常用命令学习及用法整理 ...

  10. 异构GoldenGate 12c 单向复制配置(支持DDL复制)

    1.开始配置OGG支持DDL复制(在source端操作) 1.1 赋予权限 SQL> conn /as sysdba 已连接. SQL> grant execute on utl_file ...