UVA 11624 Fire!(二次BFS)】的更多相关文章

先对火BFS一次,求出每个点的最小着火时间. 再对人BFS一次,求出走到边界的最少时间. #include <iostream> #include <queue> #include <cstring> using namespace std; int n,m,bz[1005][1005],qihuo[1005][1005]; char map[1005][1005]; int h[4][2]={-1,0,1,0,0,-1,0,1}; struct point { int…
题目传送门 /* BFS:首先对火搜索,求出火蔓延到某点的时间,再对J搜索,如果走到的地方火已经烧到了就不入队,直到走出边界. */ /************************************************ Author :Running_Time Created Time :2015-8-4 8:11:54 File Name :UVA_11624.cpp *************************************************/ #incl…
UVa 11624 - Fire!(着火了!) Time limit: 1.000 seconds Description - 题目描述 Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s…
UVA - 11624 题意:joe在一个迷宫里,迷宫的一些部分着火了,火势会向周围四个方向蔓延,joe可以向四个方向移动.火与人的速度都是1格/1秒,问j能否逃出迷宫,若能输出最小时间. 题解:先考虑模拟火,肯定是bfs(每次把同一时间着火的格子pop出来,再将它们周围的格子的t加一push进去) 然后考虑怎么模拟人,现在人处在一个会变化的迷宫中.貌似很复杂. 我们可以考虑t时刻的地图(假设我们bfs人的位置),着火的地方相当于墙壁,已经走过的地方也相当于墙壁(因为不可能回到已经走过的地方,…
题意 有一个人 有一些火 人 在每一秒 可以向 上下左右的空地走 火每秒 也会向 上下左右的空地 蔓延 求 人能不能跑出来 如果能 求最小时间 思路 有一个 坑点 火是 可能有 多处 的 样例中 只有一处 然后 先让 火 蔓延 再让人走 BFS AC代码 #include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> #include <cmath> #incl…
看题传送门 昨天晚上UVA上不去今天晚上才上得去,这是在维护么? 然后去看了JAVA,感觉还不错昂~ 晚上上去UVA后经常连接失败作死啊. 第一次做图的题~ 基本是照着抄的T T 不过搞懂了图的BFS,虽然不像二叉树的BFS那么直观. #include<cstdio> #include<queue> #include<vector> #include<cstring> #include<algorithm> using namespace std…
Fire! Time Limit: 5000MS   Memory Limit: 262144KB   64bit IO Format: %lld & %llu Description Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe esca…
算法指南白书 分别求一次人和火到达各个点的最短时间 #include<cstdio> #include<cstring> #include<queue> #include<algorithm> using namespace std; ; + ; + ; int R, C; char maze[maxr][maxc]; struct Cell { int r, c; Cell(int r, int c):r(r),c(c) {} }; ,,,}; ,,-,}…
Description Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe's location in the maze and which squares of the maze are o…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2671 首先对火进行一次bfs,得到着火时间,然后对人进行一次bfs,只允许进入还没有着火的点 注意:出迷宫条件是从任何一墙出去,过墙需要1时间 #include <cstdio> #include <cstring> #include <queue> us…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2671 题目大意:一个n*m迷宫,迷宫中有一个点'J'是人也就是起点,有多个点'F'表示着火,人每秒都可以往水平或垂直方向走,火势也可以往水平或垂直方向蔓延,火和人都不能过'#',但可以过‘.’.问人最后能否从迷宫逃出,不被火烧到. 解题思路:两次bfs,第一次求各点被火烧到的最小…
Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe's location in the maze and which squares of the maze are on fire, you…
Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s location in the maze and which squares of the maze are on fire…
题目链接 题意 人要从迷宫走出去,火会向四个方向同时扩散 分析 两步bfs,先出火到达各地时的时间(设初始时间为0,人每走一步为1s,在着一步内火可以向四周可触及的方向同时扩散),然后在bfs人,人能在某地当且仅当所到时间小于火到达时间 代码 #include<iostream> #include<queue> #include<cstring> #include<cstdio> using namespace std; const int maxn = 1…
题意:就是问你能不能在火烧到你之前,走出一个矩形区域,如果有,求出最短的时间 分析:两遍BFS,然后比较边界 #include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<cmath> #include<map> #include<queue> #include<stdlib.h> #include<s…
按白书上说的,先用一次bfs,求出每个点起火的时间 再bfs一次求出是否能够走出迷宫 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> #include<vector> using namespace std; ; << -; int r,c;//r行,c列 int d[maxn][maxn];…
题目链接:http://vjudge.net/contest/132239#problem/A 题目链接:https://uva.onlinejudge.org/external/116/11624.pdf <训练指南>P307 分析:只需要预处理每个格子起火的时间,在BFS扩展节点的时候加一个判断,到达该节点的时候,格子没有起火. 写法很巧妙,两次BFS类似,数据加一维kind,表示Joe到达该点和火到达该点. #include <bits/stdc++.h> using nam…
题目大意: F代表火焰 J代表人 一个人想在火焰烧到自己之前逃出着火地区 . 为路,人可以走,火可以燃烧(当然如果火先烧到就不能走了) #为墙,不可走 如果能逃出,输出时间,不能,输出IMPOSSIBLE 每次移动上下左右(人火都是, 花费1) 解题思路: 简单广搜两次就行,先对火广搜,保存下步数,在对人广搜,看看走到此点花费的时间是不是比火小,小的话可以走,不然不能走,走到边界为逃出条件 具体实现用一个二维数组F 先对火焰进行广搜,用来保存每个点火燃烧到时花费的步数,初始值为0:第二次广搜人走…
题目大意:在一个N*M的迷宫内,J代表某人(只有一个),F代表火(可能不只一个),#代表墙,火每分钟会向四周除了墙以外的地方扩散一层,问人能否在没被火烧到 之前逃出迷宫,若能逃出输出最短时间.很明显的bfs.但由于火到达的地方人不能抵达,故需先对火进行bfs,标记后若人在火烧到之前抵达即可.最后逃出时间需要加一, 因为当时只是抵达边界,若逃出时间需加一. #include <stdio.h> #include <queue> #include <string.h> #i…
开始刷题啦= = 痛并快乐着,学到新东西的感觉其实比看那些无脑的小说.电视剧有意思多了 bfs裸体,关键是先把所有的着火点放入队列,分开一个一个做bfs会超时的 发现vis[][]是多余的,完全可以用num[][]代替了,不过不提交了... uva的submission error跳得我蛋疼,可是介于管理员Carlos及时回复了,还是理解人家吧 #include<cstdio> #include<cstring> ; struct P{ int x,y; int c; }; P q…
E - Fire! UVA - 11624 题目描述 乔在迷宫中工作.不幸的是,迷宫的一部分着火了,迷宫的主人没有制定火灾的逃跑计划.请帮助乔逃离迷宫.根据乔在迷宫中的位置以及迷宫的哪个方块着火,你必须确定火焰烧到他之前,乔是否可以离开迷宫,如果能离开他能跑多快. 乔和火每分钟移动一个方格,上.下.左.右,四个方向中的一个.火势向四个方向同时蔓延.乔可以从迷宫的任何一个边界逃离迷宫.无论是乔还是火都不会到达有墙的位置. 输入 第一行输入包含一个整数,即测试次数 每个测试用例的第一行包含两个 整数…
11624 - Fire! Time limit: 1.000 seconds Joe works in a maze. Unfortunately, portions of the maze havecaught on re, and the owner of the maze neglected to create a reescape plan. Help Joe escape the maze.Given Joe's location in the maze and which squa…
很少用bfs进行最短路搜索,实际BFS有时候挺方便得,省去了建图以及复杂度也降低了O(N*M): UVA 11624 写的比较挫 #include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; struct node{ int ft; int sta; }flo[][]; ][]; struct person{ int x,y,t,f…
 UVA 816 -- Abbott's Revenge(BFS求最短路) 有一个 9 * 9 的交叉点的迷宫. 输入起点, 离开起点时的朝向和终点, 求最短路(多解时任意一个输出即可).进入一个交叉点的方向(用NEWS表示不同方向)不同时, 允许出去的方向也不相同. 例如:1 2 WLF NR ER * 表示如果 进去时朝W(左), 可以 左转(L)或直行(F), 如果 朝N只能右转(R) 如果朝E也只能右转.* 表示这个点的描述结束啦! 输入有: 起点的坐标, 朝向, 终点的坐标.然后是各个…
题目传送门 J - Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s location in the maze and which squares of the maze are…
也是一个走迷宫的问题,不过又有了点变化. 这里迷宫里有若干把火,而且火每秒也是向四个方向蔓延的.问人是否能走出迷宫. 我用了两遍BFS,第一遍把所有着火的格子加入队列,然后计算每个格子着火的时间. 第二遍便是走迷宫,只有当这个格子不是墙,而且当前时间在这个格子着火之前才能拓展.当然,并不是所有的空格都一定会着火. #include <cstdio> #include <cstring> #include <queue> using namespace std; stru…
题意: 迷宫里起火了,有若干个障碍物,有多个起火点,起火点每经过一个时间间隔就向它的上下左右相邻的格子扩散. 有个倒霉的人好像叫做“Joe”,他要逃出来,他每次可以向上下左右任意移动一格,但是即要避开火也要避开障碍物,问你他如果逃得出来的话至少要多少步. 没有着火点的话就直接,bfs了,但是有的话就稍微与处理一下,我们可以通过对着火点bfs,从而知道每个格子在什么时间着火. 这样的话,只要先bfs着火点,把每个格子在什么时间着火保存到数组里:然后bfs那个人,在判断他可不可以那个格子的check…
题意:某人身陷火场,总有k个点着火,着火点可向四周扩散,问此人能否逃离. 思路:可能有多个着火点,以这些着火点作为起点进行bfs,得到整个火场的最短距离,然后又以人所在坐标作为起点进行bfs,得到该人到达火场各点的最短距离.枚举边界点,如果人到达某边界点的最短距离小于最短着火点到达的距离,则说明该点可以作为逃生的出口. 该题需要注意的地方: 1.可能没有着火点.我在这里WA了 2. 对于这种数据: 1 4 4 FFFF #### .J.# .... 答案: 2 但是我的AC代码对于这种情况无法得…
题目链接 题意:J代表Joe的位置,F代表火的起点,下一刻火将会向四周扩散,求Joe逃离的最短时间,如果不能逃离输出IMPOSSIBLE; 注意火的起点可能不止一处 可以用两次bfs分别求出人到达某个位置所用时间和火到达某个位置所用时间 #include<iostream> #include<stdio.h> #include<string.h> #define INF 0xfffffff #include<queue> #include<algori…
-->Fire! 直接上中文 Descriptions: 乔在迷宫中工作.不幸的是,迷宫的一部分着火了,迷宫的主人没有制定火灾的逃跑计划.请帮助乔逃离迷宫.根据乔在迷宫中的位置以及迷宫的哪个方块着火,你必须确定火焰烧到他之前,乔是否可以离开迷宫,如果能离开他能跑多快. 乔和火每分钟移动一个方格,上.下.左.右,四个方向中的一个.火势向四个方向同时蔓延.乔可以从迷宫的任何一个边界逃离迷宫.无论是乔还是火都不会到达有墙的位置. 输入 第一行输入包含一个整数,即测试次数 每个测试用例的第一行包含两个…