hdu 1253 bfs
来源:互联网 发布:阿里云幕布申请 编辑:程序博客网 时间:2024/05/07 13:34
这个题啊 WA了N次 Time out了N次
继续加油!!
#include<iostream>#include<cstdio>#include<queue>using namespace std;#define MAXN 55int a, b, c, t, castle[MAXN][MAXN][MAXN],vist[MAXN][MAXN][MAXN];int rx[] = { 1, -1, 0, 0, 0, 0 };int ry[] = { 0, 0, 1, -1, 0, 0 };int rz[] = { 0, 0, 0, 0, 1, -1 };int scheck(int ix, int iy, int iz){if (ix < 0 || iy < 0 || iz < 0 || ix >= a || iy >= b || iz >= c || castle[ix][iy][iz] == 1 || vist[ix][iy][iz] == 1){return 0;}return 1;}int abs(int x,int a){if (x - a < 0)return a - x;return x - a;}struct node{int x, y, z, step;};int bfs(){queue<node> q;node m, n;int i, j, k,s,ss;m.x = 0;m.y = 0;m.z = 0;m.step = 0;vist[0][0][0] = 1;q.push(m);while (!q.empty()){n = q.front();q.pop();for (s = 0; s < 6; s++){m.x = n.x + rx[s];m.y = n.y + ry[s];m.z = n.z + rz[s];m.step = n.step;if (scheck(m.x,m.y,m.z) == 1){m.step++;vist[m.x][m.y][m.z] = 1;if (m.x == a - 1 && m.y == b - 1 && m.z == c - 1 && m.step <= t){return m.step;}if (abs(m.x, a-1) + abs(m.y, b-1) + abs(m.z, c-1) + m.step > t){continue;}q.push(m);}}}return -1;}int main(){freopen("TestDate.txt", "r", stdin);int test,i,j,k;scanf("%d", &test);while (test--){scanf("%d %d %d %d", &a, &b, &c, &t);for (i = 0; i < a; i++){for (j = 0; j < b; j++){for (k = 0; k < c; k++){scanf("%d", &castle[i][j][k]);}}}if (castle[a - 1][b - 1][c - 1] == 1){cout << "-1" << endl;continue;}memset(vist, 0, sizeof(vist));cout << bfs() << endl;}return 0;}
0 0
- hdu 1253 三维bfs
- HDU 1253(BFS)
- HDU[1253]--bfs
- hdu~1253(bfs)
- hdu 1253 bfs
- hdu 1253 bfs
- hdu 1253 bfs
- hdu 1253 3D bfs
- HDU bfs
- hdu 1253胜利大逃亡 bfs
- hdu-1253——三维BFS+剪枝
- hdu 1253 胜利大逃亡 BFS
- [BFS] hdu 1253 胜利大逃亡
- hdu 1253 胜利大逃亡 (三维bfs)
- hdu 1253 胜利大逃亡 (bfs)
- hdu 1253 胜利大逃亡(BFS)
- HDU 1253 胜利大逃亡(BFS)
- HDU-1253 胜利大逃亡 (BFS)
- 一看就懂的ReactJs入门教程(精华版)
- gRPC
- Android常用监听器的分类
- [HAOI2006]受欢迎的牛
- js经典赛车小游戏
- hdu 1253 bfs
- Freetype 编译 图片上显示汉字
- git简单配置和常用命令
- wireshark怎么抓包、wireshark抓包详细图文教程
- 日期问题:相隔天数
- ajax 详解
- poj-1041-John's trip(计算欧拉路)
- 21. Merge Two Sorted Lists(合并有序链表)
- ADO.NET 连接方式和非链接方式访问数据库