UVA11624 Fire! (两次BFS) 读懂题意很重要

题目:https://uva.onlinejudge.org/index.phpoption=com_onlinejudge&Itemid=8&page=show_problem&problem=2671

题意:就是迷宫着火了,火势会蔓延,Joe要逃跑,看最后能不能逃出来,但没想到败在了英语上,大家注意,题意中用的是portions,这是一个复数形式,也就是说,Joe的起点唯一,但是起火的地方并不是唯一的,这是我们首先要明确的。

思路:之前好像做到过类似的题目,当时很多人都a了,但是我没有比较好的思路,所以这次比赛的时候就看都没敢看,今日补题,觉得挺简单的啊~~~。

总的来说,就是从多个F,开始预处理出每个位置将着火的时间,然后再bfs出J位置到出口的最少时间,思路还是比较清晰的,代码也比较好写,但是不要忘记初始化时间数组,vis数组,两个队列。

代码:

#include
#include
#include
#include
#include
using namespace std;
const int maxn=1001;
char g[maxn][maxn];
int vis[maxn][maxn];
int tim[maxn][maxn];
const int inf=0x3f3f3f3f;
int n,m;
struct node{
	int x,y,t;
	node(int x_=0,int y_=0,int t_=0):x(x_),y(y_),t(t_){}
};
queueF,J;
int dr[][2]={{-1,0},{1,0},{0,1},{0,-1}};

int ok(int xx,int yy){
	return (xx>=0&&yy>=0&&xx

你可能感兴趣的:(dfs/bfs)