hdoj_1253
来源:互联网 发布:知画的真名 编辑:程序博客网 时间:2024/06/05 20:44
//BFS#include<cstdio>#include<queue>#include<cstring>using namespace std;const int maxn = 60;int G[maxn][maxn][maxn];int vis[maxn][maxn][maxn];int A, B, C, T;//节点 typedef struct node {int x, y, z;int time;}Node;//存图void read_G() {scanf("%d%d%d%d", &A, &B, &C, &T);for(int i = 0; i < A; i++) {for(int j = 0; j < B; j++) {for(int k = 0; k < C; k++) {scanf("%d", &G[i][j][k]);}}}} //逃跑判断int bfs() {//三维坐标int dir[6][3] ={{0, 1, 0}, {0, -1, 0}, {1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}};queue<Node> coor;Node S = {0, 0, 0, 0};vis[0][0][0] = 1;coor.push(S);Node temp;int x1, y1, z1;while(!coor.empty()) {temp = coor.front(); coor.pop();if(temp.x == (A-1) && temp.y == (B-1) && temp.z == (C-1) && temp.time <= T && G[A-1][B-1][C-1] == 0) return temp.time;for(int i = 0; i < 6; i++) {x1 = temp.x + dir[i][0];y1 = temp.y + dir[i][1];z1 = temp.z + dir[i][2];if(x1 < A && x1 >= 0 && y1 < B && y1 >= 0 && z1 < C && z1 >= 0 && (temp.time+1) <= T && !G[x1][y1][z1] && !vis[x1][y1][z1]) {Node temp0 = {x1, y1, z1, temp.time+1};coor.push(temp0);vis[x1][y1][z1] = 1;}}}return -1;} int main() {int t;scanf("%d", &t);while(t--) {memset(vis, 0, sizeof(vis));read_G();printf("%d\n", bfs());}return 0;}
0 0
- hdoj_1253
- jQuery中JSON与Servlet应用小例
- Spring官网下载dist.zip的几种方法
- iOS集合视图单元格高亮和选中的区别
- 2440: [中山市选2011]完全平方数 二分答案+容斥原理+莫比乌斯函数
- 设置html页面不让浏览器缓存的方法
- hdoj_1253
- 欢迎使用CSDN-markdown编辑器
- swift之表格控件简单使用(UITableview)
- C/C++研发实习生要求
- iOS --- 两个NSIndexPath对象的正确比较方式
- 国际情商12项
- 【bzoj2085】[Poi2010]Hamsters hash+倍增
- hive窗口函数理解加实践
- iOS 下实际网络连接状态