HDU 1253 (简单三维广搜) 胜利大逃亡
2014-08-15 23:51
302 查看
奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz
而且我也优化过了的啊,尼玛还是一直爆!
先把代码贴上睡觉去了,明天再来弄
代码君
而且我也优化过了的啊,尼玛还是一直爆!
先把代码贴上睡觉去了,明天再来弄
//#define LOCAL #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 50*50*50+100; int head, tail; struct Point { int x, y, z; int steps; }qu[maxn]; int a, b, c, m; int map[52][52][52]; int dir[6][3] = {{1,0,0}, {-1,0,0}, {0,1,0}, {0,-1,0}, {0,0,1}, {0,0,-1}}; bool islegal(int x, int y, int z) { return (x>=0 && x<a && y>=0 && y<b && z>=0 && z<c && (map[x][y][z] == 0)); } void BFS(void) { qu[0].x = qu[0].y = qu[0].z = qu[0].steps = 0; head = 0, tail = 1; while(head < tail) { if(qu[head].steps > m) {printf("-1\n"); return;} if(qu[head].x==a-1 && qu[head].y==b-1 && qu[head].z==c-1) {printf("%d\n", qu[head].steps); return;} for(int i = 0; i < 6; ++i) { int xx = qu[head].x + dir[i][0]; int yy = qu[head].y + dir[i][1]; int zz = qu[head].z + dir[i][2]; if(islegal(xx, yy, zz)) { map[xx][yy][zz] = 1; if(a+b+c-3-xx-yy-zz > m-qu[head].steps-1) //优化 continue; qu[tail].x = xx; qu[tail].y = yy; qu[tail].z = zz; qu[tail++].steps = qu[head].steps + 1; } } ++head; } printf("-1\n"); } int main(void) { #ifdef LOCAL freopen("1253in.txt", "r", stdin); #endif int T; scanf("%d", &T); while(T--) { scanf("%d%d%d%d", &a, &b, &c, &m); for(int i = 0; i < a; ++i) for(int j = 0; j < b; ++j) for(int k = 0; k < c; ++k) scanf("%d", &map[i][j][k]); //map[0][0][0] = 1; BFS(); } return 0; }
代码君
相关文章推荐
- HDU-1253 胜利大逃亡(简单三维广搜BFS)
- hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)
- hdu 1253 胜利大逃亡(广搜,队列,三维,简单)
- HDU 1253 胜利大逃亡(简单三维BFS)
- hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)
- HDU 1253:胜利大逃亡(简单三维BFS)
- HDU 1253 胜利大逃亡(简单三维广度优先搜索)
- HDU 1253:胜利大逃亡(简单三维BFS)
- hdu 1253 胜利大逃亡 三维 BFS+剪技
- hdu 1253 胜利大逃亡(三维bfs)
- HDU 1253 胜利大逃亡(三维BFS)
- hdu 1253 胜利大逃亡 三维bfs 解题报告
- [ACM] hdu 1253 胜利大逃亡 (三维BFS)
- HDU 1253 - 胜利大逃亡(三维搜索)
- HDU 1253 胜利大逃亡 三维BFS
- hdu 1253 胜利大逃亡(简单题)
- hdu 1253 胜利大逃亡(BFS,三维)
- hdu 1253 胜利大逃亡_三维
- HDU 1253-胜利大逃亡(裸三维BFS)
- HDU1253 胜利大逃亡(三维广搜BFS+剪枝+优先队列)