HDU 1072 Nightmare
来源:互联网 发布:淘宝高达模型店推 编辑:程序博客网 时间:2024/05/20 17:38
题目链接:Nightmare
解题思路:这道题目也是简单的广搜,主要处理好炸弹的状态就好了。
#include<cstdio>#include<cstring>#include<queue>#define MAX 10#define MAXT 7using namespace std;struct node{ int x, y, s, t; node(){} node(int xx, int yy, int tt, int ss){ x = xx, y = yy, t = tt, s = ss; }};bool v[MAX][MAX][MAXT];int g[MAX][MAX];int n, m;int dir[4][2] = {1,0,-1,0,0,1,0,-1};int sx, sy;bool check(int x, int y){ if(x < 0 || x >= n || y < 0 || y >= m || g[x][y] == 0){ return false; } return true;}int bfs(){ int i, j, k; queue<node> mq; memset(v, false, sizeof(v)); mq.push(node(sx, sy, 6, 0)); v[sx][sy][6] = true; while(!mq.empty()){ node s = mq.front(); //printf("%d %d %d %d\n", s.x, s.y, s.t, s.s); mq.pop(); for(i = 0; i < 4; i++){ int xx = s.x + dir[i][0]; int yy = s.y + dir[i][1]; int tt = s.t - 1; int ss = s.s + 1; if(check(xx, yy) && !v[xx][yy][tt] && tt > 0){ v[xx][yy][tt] = true; if(g[xx][yy] == 3){ return ss; } else if(g[xx][yy] == 4){ mq.push(node(xx, yy, 6, ss)); v[xx][yy][6] = true; } else{ mq.push(node(xx, yy, tt, ss)); } } } } return -1;}int main(){ int i, j, k, t; scanf("%d", &t); while(t--){ scanf("%d%d", &n, &m); for(i = 0; i < n; i++){ for(j = 0; j < m; j++){ scanf("%d", &g[i][j]); if(g[i][j] == 2){ sx = i, sy = j; } } } printf("%d\n", bfs()); } return 0;}
0 0
- HDU 1072 Nightmare
- BFS hdu 1072 Nightmare
- HDU 1072 Nightmare BFS
- HDU 1072 Nightmare
- hdu 1072 Nightmare BFS
- hdu Nightmare 1072
- Hdu 1072 - Nightmare
- hdu 1072 Nightmare bfs
- HDU-1072:Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare
- HDU-1072-Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare
- Nightmare hdu 1072
- hdu 1072 Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare(搜索)
- 我如何把薪水从 50人民币/天 提升到 100美元/小时的 (1)
- 通过GeoIP2分析访问者IP获取地理位置信息
- Maximal Rectangle
- JAVA线程池的简单实现及优先级设置
- 数据结构
- HDU 1072 Nightmare
- css3+html5新特性
- 分布式系统阅读笔记(二)----系统模型
- 项目四:日期结构体
- 第十七周项目 4 日期结构体——该年第几天
- OpenGL实现3D立体显示
- 我如何把薪水从 50人民币/天 提升到 100美元/小时的 (2)
- 游戏开发视频教程_基于MFC设计的MINI快跑游戏
- HDU 4403 A very hard Aoshu problem