ZOJ 1649 Rescue(有敌人迷宫BFS)
题意 求迷宫中从a的位置到r的位置须要的最少时间 经过'.'方格须要1s 经过‘x’方格须要两秒 '#'表示墙
因为有1s和2s两种情况 须要在基础迷宫bfs上加些推断
令到达每一个点的时间初始为无穷大 当从一个点到达该点用的时间比他本来的时间小时 更新这个点的时间并将这个点入队 扫描全然图就得到答案咯
- #include<cstdio>
- #include<cstring>
- #include<queue>
- using namespace std;
- const int N = 205;
- char mat[N][N];
- int time[N][N], sx, sy;
- int dx[4] = {0, 0, -1, 1};
- int dy[4] = { -1, 1, 0, 0};
- struct grid
- {
- int x, y;
- grid(int xx = 0, int yy = 0): x(xx), y(yy) {}
- };
- void bfs()
- {
- memset(time, 0x3f, sizeof(time));
- time[sx][sy] = 0;
- queue<grid> g;
- g.push(grid(sx, sy));
- while(!g.empty())
- {
- grid cur = g.front();
- g.pop();
- int cx = cur.x, cy = cur.y, ct = time[cx][cy];
- for(int i = 0; i < 4; ++i)
- {
- int nx = cx + dx[i], ny = cy + dy[i];
- if(mat[nx][ny] && mat[nx][ny] != '#')
- {
- int tt = ct + 1;
- if(mat[cx][cy] == 'x') ++tt;
- if(tt < time[nx][ny])
- {
- time[nx][ny] = tt;
- g.push(grid(nx, ny));
- }
- }
- }
- }
- }
- int main()
- {
- int n, m, ex, ey;
- while (~scanf("%d%d", &n, &m))
- {
- memset(mat, 0, sizeof(mat));
- for(int i = 1; i <= n; ++i)
- scanf("%s", mat[i] + 1);
- for(int i = 1; i <= n; ++i)
- for(int j = 1; j <= m; ++j)
- if(mat[i][j] == 'a') sx = i, sy = j;
- else if(mat[i][j] == 'r') ex = i, ey = j;
- bfs();
- if(time[ex][ey] != time[0][0])
- printf("%d\n", time[ex][ey]);
- else
- printf("Poor ANGEL has to stay in the prison all his life.\n");
- }
- return 0;
- }
ZOJ 1649 Rescue(有敌人迷宫BFS)的更多相关文章
- zoj 1649 Rescue (BFS)(转载)
又是类似骑士拯救公主,不过这个是朋友拯救天使的故事... 不同的是,天使有多个朋友,而骑士一般单枪匹马比较帅~ 求到达天使的最短时间,杀死一个护卫1 units time , 走一个格子 1 unit ...
- zoj 1649 Rescue
BFS..第一次使用C++ STL的队列来写广搜. #include<stdio.h> #include<string.h> #include<math.h> #i ...
- BFS zoj 1649
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1649 //hnldyhy(303882171) 11:12:46 // z ...
- ZOJ 1649:Rescue(BFS)
Rescue Time Limit: 2 Seconds Memory Limit: 65536 KB Angel was caught by the MOLIGPY! He was put ...
- HDU 1242 Rescue(BFS),ZOJ 1649
题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...
- ZOJ 649 Rescue(优先队列+bfs)
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- zoj 1649 bfs
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- poj 1383 Labyrinth【迷宫bfs+树的直径】
Labyrinth Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 4004 Accepted: 1504 Descrip ...
随机推荐
- [Apple开发者帐户帮助]三、创建证书(4)创建Safari签名证书
您的Safari扩展程序必须由Apple颁发的证书签名,您可以在开发者帐户中创建和下载该证书. 在“ 证书”,“标识符和配置文件”中,从左侧的弹出菜单中选择“Safari扩展”. 在“证书”下,选择“ ...
- [Apple开发者帐户帮助]二、管理你的团队(3)删除团队成员
如果您已加入Apple开发者计划,您将在App Store Connect中管理团队成员.有关详细信息,请转到App Store Connect帮助中的添加和编辑用户. 如果您已加入Apple Dev ...
- Java.Cas4.0客户端接入配置
1.本示例中使用cas4.0+cas-client-core3.4版本,ide则是myeclipse2014 blue版本,mvn使用3.9版本 2.注意事项:请先实现破解cas-client-cor ...
- HDU 1054 Hungary
Strategic Game Problem Description Bob enjoys playing computer games, especially strategic games, bu ...
- Spring Boot (13) druid监控
druid druid是和tomcat jdbc一样优秀的连接池,出自阿里巴巴.除了连接池,druid哈hi有一个很实用的监控功能. pom.xml 添加了以下依赖后,会自动用druid连接池替代默认 ...
- Linux的那点事
1.重启nginx服务器 注意,修改了nginx配置文件后最好先检查一下修改过的配置文件是否正确,以免重启后Nginx出现错误影响服务器稳定运行. 判断Nginx配置是否正确命令如下: nginx - ...
- node函数buf.readDoubleBE详解
offset {Number} 0 noAssert {Boolean} 默认:false 返回:{Number} 从该 Buffer 指定的带有特定尾数格式(readDoubleBE() 返回一个较 ...
- Table is specified twice, both as a target for 'UPDATE' and as a separate source
UPDATE Bins b SET b.ShopSn =’111201611111168706’ WHERE b.Id IN (SELECT b.Id FROM Bins b JOIN BinInve ...
- 安卓代码迁移:Make.exe: *** [libs/armabi-v7a/gdbserver] Error 1
解决办法1:安装ndk和eclipse修改为x86操作系统 解决办法2:降低更换NDK版本
- 实现Android-JNI本地C++调试
1. 原文链接:NDK单步调试方法 如有问题或者版权要求,请拜访原作者或者通知本人. 最近为了性能需求,开始搞JNI,白手起搞真心不容易.中间差点崩溃了好几次,最终总算得到一点心得. JN ...