题意,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. Git Step by Step – (6) Git远程仓库

    前面文章中出现的所有Git操作都是基于本地仓库的,但是日常工作中需要多人合作,不可能一直都在自己的代码仓库工作.所以,这里我们就开始介绍Git远程仓库. 在Git系统中,用户可以通过push/pull ...

  2. ios开发之--仿(微信)自定义表情键盘

    先附上demo:https://github.com/hgl753951/CusEmoji.git 效果图如下:

  3. webstorm批量查找,批量替换快捷键

    ctrl+shift+f:批量查找,我的webstorm11不能用ctrl+shift+f进行批量查找了,不知道什么原因,自己又胡乱实验了一下, 发现ctrl+shift+g+f可以批量查找 ctrl ...

  4. linux-满足多字符条件统计行数

    测试数据: 2017-10-24 14:14:11:1123 [ INFO] order_type=add,order_id=9150882564978710367790292017-10-24 14 ...

  5. HttpClient(四)-- 使用代理IP 和 超时设置

    1.代理IP的用处: 在爬取网页的时候,有的目标站点有反爬虫机制,对于频繁访问站点以及规则性访问站点的行为,会采集屏蔽IP措施.这时候,就可以使用代理IP,屏蔽一个就换一个IP. 2.代理IP分类: ...

  6. php-fpm 记录慢执行日志

    有时候我们访问一个 php 的网站很慢,要想知道慢的原因,需要配置 php-fpm.conf,记录执行慢的日志: [root@localhost ~]$ cat /usr/local/php/etc/ ...

  7. ajax二级联动代码实例

    //二级联动 $(function () { var _in_progress = false; function check_in_progress() { if (_in_progress == ...

  8. css 去除页面双击事件

    -ms-touch-action: manipulation !important;

  9. Linux学习(二)

    Linux进程管理 每个 Linux 命令都与系统中的程序对应,输入命令,Linux 就会创建一个新的进程.例如使用 ls 命令遍历目录中的文件时,就创建了一个进程.简而言之,进程就是程序的实例. 创 ...

  10. 【十大算法实现之naive bayes】朴素贝叶斯算法之文本分类算法的理解与实现

    关于bayes的基础知识,请参考: 基于朴素贝叶斯分类器的文本聚类算法 (上) http://www.cnblogs.com/phinecos/archive/2008/10/21/1315948.h ...