hdu 1253 胜利大逃亡
来源:互联网 发布:2014年2月宏观经济数据 编辑:程序博客网 时间:2024/05/16 01:21
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1253
#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;const int MAXN = 55;const int INF = 0xffffff;int Graph[MAXN][MAXN][MAXN];int MinTime[MAXN][MAXN][MAXN];struct Node{ int x, y, z; int step; Node() { x = y = z = 0; step = 0; }};Node TargetPos;int level, row, col;int dir[6][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {-1, 0, 0},{0, -1, 0}, {0, 0, -1}};bool Is_CanGo(Node CurPos){ if(CurPos.x < 0 || CurPos.x >= level || CurPos.y < 0 || CurPos.y >= row || CurPos.z < 0 || CurPos.z >= col || Graph[CurPos.x][CurPos.y][CurPos.z] == 1) return false; return true;}void BFS(Node S){ queue <Node> Que; Que.push(S); while(!Que.empty()) { Node Curpos = Que.front(); Que.pop(); for(int i = 0; i < 6; ++i) { Node t; t.x = Curpos.x + dir[i][0]; t.y = Curpos.y + dir[i][1]; t.z = Curpos.z + dir[i][2]; if(Is_CanGo(t)) { t.step = Curpos.step + 1; if(t.step < MinTime[t.x][t.y][t.z]) { MinTime[t.x][t.y][t.z] = t.step; Que.push(t); } } } }}int main(){ int T; int Retime; Node StartPos; scanf("%d", &T); while(T--) { scanf("%d %d %d %d", &level, &row, &col, &Retime); for(int i = 0; i < level; ++i) { for(int j = 0; j < row; ++j) { for(int z = 0; z < col; ++z) { MinTime[i][j][z] = INF; scanf("%d", &Graph[i][j][z]); } } } StartPos.x = 0, StartPos.y = 0, StartPos.z = 0,StartPos.step = 0; TargetPos.x = level-1, TargetPos.y = row-1, TargetPos.z = col-1; //MinTime[StartPos.x][StartPos.y][StartPos.z] = 0; BFS( StartPos ); int t = MinTime[TargetPos.x][TargetPos.y][TargetPos.z]; if(t <= Retime && t != -1) printf("%d\n", t); else printf("-1\n"); } return 0;}
0 0
- hdu 1253 胜利大逃亡
- hdu 1253 胜利大逃亡
- HDU 1253 胜利大逃亡
- HDU 1253 胜利大逃亡
- HDU-1253-胜利大逃亡
- hdu 1253 胜利大逃亡
- HDU-1253:胜利大逃亡
- hdu 1253 胜利大逃亡
- hdu 1253 胜利大逃亡
- hdu 1253 胜利大逃亡
- HDU 1253 胜利大逃亡
- hdu 1253 胜利大逃亡
- HDU-1253-胜利大逃亡
- hdu 1253 胜利大逃亡
- hdu 1253 胜利大逃亡
- hdu-1253-胜利大逃亡
- HDU-1253-胜利大逃亡
- hdu 1253 胜利大逃亡
- 1088
- 《爸爸去哪儿》孩子们生活照
- 啤酒和饮料
- java jvm内存
- The server quit without updating PID file (/var/run/mysqld/mysqld.pid)
- hdu 1253 胜利大逃亡
- 正则表达式在java中的简单运用
- 16进制的简单运算(不同进制的计算,输入,输出)
- C++个人学习笔记01
- 关于onTouchEvent()和onTouch()的区别
- 华硕K40in黑苹果更新USB热插拔支持
- linux下基于qt软键盘的设计
- 全志A20单独烧录内核
- 写给程序员的编程语言科普——前言