uva 11624 Fire! 【 BFS 】
按白书上说的,先用一次bfs,求出每个点起火的时间
再bfs一次求出是否能够走出迷宫
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #include<queue>
- #include<vector>
- using namespace std;
- const int maxn = ;
- const int INF = << -;
- int r,c;//r行,c列
- int d[maxn][maxn];
- int vis[maxn][maxn];
- char g[maxn][maxn];
- int sx,sy;
- int dir[][] = {,,-,,,,,-};
- struct node{
- int x,y;
- int step;
- }p[maxn];
- queue<node> Q;
- void bfs1(){
- memset(vis,,sizeof(vis));
- while(!Q.empty()){
- node v = Q.front();Q.pop();
- for(int i = ;i < ;i++){
- int xx = v.x + dir[i][];
- int yy = v.y + dir[i][];
- if(xx < || xx > r || yy < || yy > c || vis[xx][yy] || g[xx][yy] != '.') continue;
- vis[xx][yy] = ;
- d[xx][yy] = min(d[xx][yy],v.step+);
- Q.push(node{xx,yy,v.step+});
- }
- }
- }
- void bfs2(){
- queue<node> q;
- memset(vis,,sizeof(vis));
- q.push(node{sx,sy,});vis[sx][sy] = ;
- while(!q.empty()){
- node u = q.front();q.pop();
- if(u.x == r || u.y == c || u.x == || u.y == ){
- printf("%d\n",u.step + );
- return;
- }
- for(int i = ;i < ;i++){
- int xx = u.x + dir[i][];
- int yy = u.y + dir[i][];
- if(xx < || xx > r || yy < || yy > c || vis[xx][yy] || g[xx][yy] != '.') continue;
- if(u.step + >= d[xx][yy]) continue;
- vis[xx][yy] = ;
- q.push(node{xx,yy,u.step+});
- }
- }
- puts("IMPOSSIBLE");
- }
- int main(){
- int T;
- scanf("%d",&T);
- while(T--){
- while(!Q.empty()) Q.pop();
- scanf("%d %d",&r,&c);
- for(int i = ;i <= r;i++){
- for(int j = ;j <= c;j++) d[i][j] = INF;
- }
- for(int i = ;i <= r;i++){
- for(int j = ;j <= c;j++) {
- cin>>g[i][j];
- if(g[i][j] == 'F') Q.push(node{i,j,});
- if(g[i][j] == 'J') sx = i,sy = j;
- }
- }
- bfs1();
- bfs2();
- }
- return ;
- }
加油~~~gooooooo~~
uva 11624 Fire! 【 BFS 】的更多相关文章
- UVA - 11624 Fire! 【BFS】
题意 有一个人 有一些火 人 在每一秒 可以向 上下左右的空地走 火每秒 也会向 上下左右的空地 蔓延 求 人能不能跑出来 如果能 求最小时间 思路 有一个 坑点 火是 可能有 多处 的 样例中 只有 ...
- UVA 11624 - Fire! 图BFS
看题传送门 昨天晚上UVA上不去今天晚上才上得去,这是在维护么? 然后去看了JAVA,感觉还不错昂~ 晚上上去UVA后经常连接失败作死啊. 第一次做图的题~ 基本是照着抄的T T 不过搞懂了图的BFS ...
- UVa 11624 Fire!(BFS)
Fire! Time Limit: 5000MS Memory Limit: 262144KB 64bit IO Format: %lld & %llu Description Joe ...
- (简单) UVA 11624 Fire! ,BFS。
Description Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the ow ...
- UVA - 11624 Fire! 双向BFS追击问题
Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of ...
- UVA_11624 Fire! 【BFS】
一.题面 略 二.题意分析 一个迷宫中,有一个人Joe和一个或多个起火点,起火点可以蔓延,人可以走动,都只能走4个方向,问人能走出去的最少步数,如果不能输出不可能.很多大佬说是两遍BFS,先一遍火,记 ...
- BFS(两点搜索) UVA 11624 Fire!
题目传送门 /* BFS:首先对火搜索,求出火蔓延到某点的时间,再对J搜索,如果走到的地方火已经烧到了就不入队,直到走出边界. */ /******************************** ...
- UVa 11624 Fire!(着火了!)
UVa 11624 - Fire!(着火了!) Time limit: 1.000 seconds Description - 题目描述 Joe works in a maze. Unfortunat ...
- UVA 11624 Fire!【两点BFS】
Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the m ...
随机推荐
- python编写简单的html登陆页面(3)
1 在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将静态分配数据,建立表格,存放学生信息 2 加载到静态数据 3 html的编写直接在表格里添加一组数据就行了 4 V ...
- 如何在IE11中设置兼容模式?设置的具体方法
IE11浏览器软件版本:简体中文正式版 For Win7网络工具立即查看 1.同样进入需要兼容性模式的网站,点击菜单栏位工具--F12开发者人员工具!如下图所示. 2.在开发者选项左下侧菜单栏位,点击 ...
- day27-1 numpy模块
目录 numpy array 一维数组 二维数组(用的最多) np.array和list的区别 获取多维数组的行和列 多维数组的索引 高级功能 多维数组的元素替换 多维数组的合并 通过函数方法创建多维 ...
- 数据结构(3) 第三天 栈的应用:就近匹配/中缀表达式转后缀表达式 、树/二叉树的概念、二叉树的递归与非递归遍历(DLR LDR LRD)、递归求叶子节点数目/二叉树高度/二叉树拷贝和释放
01 上节课回顾 受限的线性表 栈和队列的链式存储其实就是链表 但是不能任意操作 所以叫受限的线性表 02 栈的应用_就近匹配 案例1就近匹配: #include <stdio.h> in ...
- 在小程序中实现全局混入,以混入的形式扩展小程序的api
GitHub: https://github.com/WozHuang/mp-extend 相关文章: 小程序全局状态管理,在页面中获取globalData和使用globalSetData 通过页面预 ...
- BZOJ 2716/2648 SJY摆棋子 (三维偏序CDQ+树状数组)
题目大意: 洛谷传送门 这明明是一道KD-Tree,CDQ分治是TLE的做法 化简式子,$|x1-x2|-|y1-y2|=(x1+y1)-(x2+y2)$ 而$CDQ$分治只能解决$x1 \leq x ...
- [POJ 3621] Sighting Cows
01分数规划的基本裸题. 因为路线一定是个环,所以找个最优比率生成环即可 二分一个比值,check一下即可. #include <queue> #include <cstdio> ...
- JavaScript基础简介
JavaScript引入的方式 直接在<script>标签中写 <script> console.log('hello world!'); </script> 引入 ...
- TensorFlow 制作自己的TFRecord数据集
官网的mnist和cifar10数据之后,笔者尝试着制作自己的数据集,并保存,读入,显示. TensorFlow可以支持cifar10的数据格式, 也提供了标准的TFRecord 格式,而关于 ten ...
- ioremap映射函数
一.ioremap() 函数 Linux在io.h头文件中声明了函数ioremap(),用来将I/O内存资源的物理地址映射到核心虚地址空间(3GB-4GB)中(这里是内核空间),原型如下: 1.ior ...