题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2671 题目大意:一个n*m迷宫,迷宫中有一个点'J'是人也就是起点,有多个点'F'表示着火,人每秒都可以往水平或垂直方向走,火势也可以往水平或垂直方向蔓延,火和人都不能过'#',但可以过‘.’.问人最后能否从迷宫逃出,不被火烧到. 解题思路:两次bfs,第一次求各点被火烧到的最小…
题目链接 题意 人要从迷宫走出去,火会向四个方向同时扩散 分析 两步bfs,先出火到达各地时的时间(设初始时间为0,人每走一步为1s,在着一步内火可以向四周可触及的方向同时扩散),然后在bfs人,人能在某地当且仅当所到时间小于火到达时间 代码 #include<iostream> #include<queue> #include<cstring> #include<cstdio> using namespace std; const int maxn = 1…
题目链接: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…
先对火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…
题意:就是问你能不能在火烧到你之前,走出一个矩形区域,如果有,求出最短的时间 分析:两遍BFS,然后比较边界 #include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<cmath> #include<map> #include<queue> #include<stdlib.h> #include<s…
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! 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…
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…
看题传送门 昨天晚上UVA上不去今天晚上才上得去,这是在维护么? 然后去看了JAVA,感觉还不错昂~ 晚上上去UVA后经常连接失败作死啊. 第一次做图的题~ 基本是照着抄的T T 不过搞懂了图的BFS,虽然不像二叉树的BFS那么直观. #include<cstdio> #include<queue> #include<vector> #include<cstring> #include<algorithm> using namespace std…
算法指南白书 分别求一次人和火到达各个点的最短时间 #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…
按白书上说的,先用一次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];…
题目大意: 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…
路线冲突问题 题目描述 给出一张地图,地图上有n个点,任意两点之间有且仅有一条路.点的编号从1到n. 现在兵团A要从s1到e1,兵团B要从s2到e2,问两条路线是否会有交点,若有则输出交点个数,否出输出”success”. 输入 多组输入. 对于每组输入. 第一行输入n(1 <= n <= 100000),代表点的个数. 接下来的n-1行,每行包含两个整数u,v(1 <= u,v <= n),代表u,v之间有一条相连. 再接下里的一行包含四个整数s1,e1,s2,e2(1 <…
E - Fire! UVA - 11624 题目描述 乔在迷宫中工作.不幸的是,迷宫的一部分着火了,迷宫的主人没有制定火灾的逃跑计划.请帮助乔逃离迷宫.根据乔在迷宫中的位置以及迷宫的哪个方块着火,你必须确定火焰烧到他之前,乔是否可以离开迷宫,如果能离开他能跑多快. 乔和火每分钟移动一个方格,上.下.左.右,四个方向中的一个.火势向四个方向同时蔓延.乔可以从迷宫的任何一个边界逃离迷宫.无论是乔还是火都不会到达有墙的位置. 输入 第一行输入包含一个整数,即测试次数 每个测试用例的第一行包含两个 整数…
很少用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…
也是一个走迷宫的问题,不过又有了点变化. 这里迷宫里有若干把火,而且火每秒也是向四个方向蔓延的.问人是否能走出迷宫. 我用了两遍BFS,第一遍把所有着火的格子加入队列,然后计算每个格子着火的时间. 第二遍便是走迷宫,只有当这个格子不是墙,而且当前时间在这个格子着火之前才能拓展.当然,并不是所有的空格都一定会着火. #include <cstdio> #include <cstring> #include <queue> using namespace std; stru…
传送门: http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2031 Description The Barareh village is on fire due to the attack of the virtual enemy. Several places are already on fire and the fire is spreading fast to other places. Khorzookhan who is the…
-->Fire! 直接上中文 Descriptions: 乔在迷宫中工作.不幸的是,迷宫的一部分着火了,迷宫的主人没有制定火灾的逃跑计划.请帮助乔逃离迷宫.根据乔在迷宫中的位置以及迷宫的哪个方块着火,你必须确定火焰烧到他之前,乔是否可以离开迷宫,如果能离开他能跑多快. 乔和火每分钟移动一个方格,上.下.左.右,四个方向中的一个.火势向四个方向同时蔓延.乔可以从迷宫的任何一个边界逃离迷宫.无论是乔还是火都不会到达有墙的位置. 输入 第一行输入包含一个整数,即测试次数 每个测试用例的第一行包含两个…
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…
题目链接 题意:J代表Joe的位置,F代表火的起点,下一刻火将会向四周扩散,求Joe逃离的最短时间,如果不能逃离输出IMPOSSIBLE; 注意火的起点可能不止一处 可以用两次bfs分别求出人到达某个位置所用时间和火到达某个位置所用时间 #include<iostream> #include<stdio.h> #include<string.h> #define INF 0xfffffff #include<queue> #include<algori…
题意:给出n个点,m条边的无向图,每条边有一种颜色,求从结点1到结点n颜色字典序最小的最短路径. 析:首先这是一个最短路径问题,应该是BFS,因为要保证是路径最短,还要考虑字典序,感觉挺麻烦的,并不好做,事实用两次BFS, 第一次是倒序BFS,目的是得到从结点 i 到结点n的最短距离,然后再从第一个点开始到最后一个,要保证在查找时,每经过一点要让d值恰好减少1, 直到终点,这也是一个BFS,因为这个字典序在某个结点是一样的,所以是两个BFS,我超时了好几次,因为少写了一个vis, 一定要细心,…
Description Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.  Yifenfei's home is at the countryside, but Merceki's home is in th…