Fire Game

题意:

两个小朋友可以任选一块草地点火,草地可以不同,也可以相同,问最少的烧光草地的时间。

思路:

一开始看到这个以为是联通块计数,没想到这道题通过枚举两个起始点作为队列的初始点,每次跑一边bfs即可。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFFLL; //
const ll nmos = 0x80000000LL; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3fLL; //
const int mod = 1e9+; const double PI=acos(-1.0); // #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------showtime----------------------*/
const int maxn = ;
int n,m;
string mp[maxn];
int dp[maxn][maxn]; int nt[][] = {
{,},{,},{-,},{,-},
};
struct node
{
int x,y,step;
}q[maxn*maxn];
int mx,tot;
void bfs(node a,node b){
mx = ;
for(int i=; i<maxn; i++){
for(int j=; j<maxn; j++)dp[i][j] = inf;
}
queue<node>que;
que.push(a);
if(a.x!=b.x||a.y!=b.y)que.push(b);
dp[a.x][a.y] = ;
dp[b.x][b.y] = ;
while(!que.empty()){
int x = que.front().x,y = que.front().y,s = que.front().step;
que.pop();
for(int i= ; i<; i++){
int nx = x + nt[i][],ny = y + nt[i][];
if(nx < ||nx >=n || ny <||ny>=m)continue;
if(mp[nx][ny]=='.')continue;
if(dp[nx][ny] > s + ){
dp[nx][ny] = s + ;
mx = max(mx,s+);
node tmp={nx,ny,s+};
que.push(tmp); }
}
}
}
void solve(){
cin>>n>>m; for(int i=; i<n; i++){
cin>>mp[i];
}
int cnt = ,ans = inf;
for(int i=; i<n ; i++){
for(int j=; j<m; j++){
if(mp[i][j]=='#'){
q[++cnt].x = i;
q[cnt].y = j;
q[cnt].step = ;
}
}
} for(int i=; i<=cnt; i++)
{ for(int j=i; j<=cnt; j++){
bfs(q[i],q[j]);
int flag = ;
for(int x = ; x < n; x++){
for(int y = ; y<m; y++){
if(dp[x][y] >=inf && mp[x][y] == '#')flag= ;
}
}
if(flag)ans = min(ans, mx); }
}
if(ans < inf)cout<<ans<<endl;
else cout<<-<<endl;
}
int main(){
int T; cin>>T;
for(int t=;t<=T;t++){
cout<<"Case "<<t<<": ";
solve();
}
return ;
}

FZU-2150

FZU - 2150-Fire Game BFS-枚举的更多相关文章

  1. FZU - 2150 Fire Game bfs+双起点枚举

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

  2. (FZU 2150) Fire Game (bfs)

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

  3. 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 ...

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

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

  5. fzu 2150 Fire Game 【身手BFS】

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

  6. FZU 2150 Fire Game (暴力BFS)

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

  7. FZU 2150 fire game (bfs)

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

  8. FZU 2150 Fire Game

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

  9. FZU 2150 Fire Game 【两点BFS】

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

  10. FZU 2150 Fire Game(BFS)

    点我看题目 题意 :就是有两个熊孩子要把一个正方形上的草都给烧掉,他俩同时放火烧,烧第一块的时候是不花时间的,每一块着火的都可以在下一秒烧向上下左右四块#代表草地,.代表着不能烧的.问你最少花多少时间 ...

随机推荐

  1. web安全脑图

  2. PHP xdebug API接口优化揪出了getimagesize这个鬼

    在API优化list中,公司客户系统的服务号客服有个获取聊天消息的接口getHistory请求时间很长,就去优化了下,记下过程. 一,配置环境,追踪使用Xdebug: 1.在https://xdebu ...

  3. .net core 实现基于 cron 表达式的任务调度

    .net core 实现基于 cron 表达式的任务调度 Intro 上次我们实现了一个简单的基于 Timer 的定时任务,详细信息可以看这篇文章. 但是使用过程中慢慢发现这种方式可能并不太合适,有些 ...

  4. 第十章 Fisco Bcos 权限控制下的数据上链实操演练

    一.目的 前面已经完成fisco bcos 相关底层搭建.sdk使用.控制台.webase中间件平台等系列实战开发, 本次进行最后一个部分,体系化管理区块链底层,建立有序的底层控管制度,实现权限化管理 ...

  5. Java | Map排序,工具类改进

    package util; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; ...

  6. opencv图像直方图均衡化及其原理

    直方图均衡化是什么有什么用 先说什么是直方图均衡化,通俗的说,以灰度图为例,原图的某一个像素为x,经过某个函数变为y.形成新的图.新的图的灰度值的分布是均匀的,这个过程就叫直方图均衡化. 图像直方图均 ...

  7. openjdk:8u22-jre-alpine在java开发中的NullPointerException错误解决方案

    问题描述 ** 在SpringBoot项目中使用了Ureport报表组件, 打包发布部署到docker中启动报错 ** java.lang.NullPointerException at sun.aw ...

  8. java并发编程(十三)----(JUC原子类)引用类型介绍(CAS和ABA的介绍)

    这一节我们将探讨引用类型原子类:AtomicReference, AtomicStampedRerence, AtomicMarkableReference.AtomicReference的使用非常简 ...

  9. 三层架构(MVC)实现简单登陆注册验证(含验证码)

    前言在我的上一篇微博里我已经提出了登陆的方法,当时我采取的是纯servlet方式,因为当时刚接触到servlet,正好网上没有这方面的全面讲解,所以我就发飙了.不过在现实生产中我们大多采用的三层架构. ...

  10. 把Python项目打包成exe文件

    我们很多时候,写好的程序需要打包成.exe文件才可以发给客户,那么今天我就来谈一谈,如何将一个写好的Python程序打包成exe文件! 首先,我们我们使用到的工具是python 3.7 和 Pyins ...