胜利大逃亡hdu1253三维bfs
来源:互联网 发布:小蚂蚁微信编辑器源码 编辑:程序博客网 时间:2024/05/01 14:41
传送门:hdu1253
看题立马明白是bfs,但是很容易超时,所以要做适当的剪枝。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int go[6][3]={0,1,0,1,0,0,0,-1,0,-1,0,0,0,0,1,0,0,-1};int map[55][55][55];int book[55][55][55];struct node{int x,y,z;int time;}q[125005];int a,b,c,t;int bfs(){int head=1,tail=1;q[head].x=0;q[head].y=0;q[head].z=0;q[head].time=0;book[0][0][0]=1;tail++;while(head<tail){if(q[head].x==a-1&&q[head].y==b-1&&q[head].z==c-1&&q[head].time<=t)return q[head].time;for(int i=0;i<6;i++){int tx=q[head].x+go[i][2];int ty=q[head].y+go[i][1];int tz=q[head].z+go[i][0];if(abs(a-tx+1)+abs(a-ty+1)+abs(a-tz+1)+q[head].time+1>t)//如果转移到的下一点用最短路径都无法到达终点,则直接continue; //舍弃 if(!book[tx][ty][tz]&&map[tx][ty][tz]==0&&0<=tx&&tx<a&&0<=ty&&ty<b&&0<=tz&&tz<c){q[tail].x=tx;q[tail].y=ty;q[tail].z=tz;q[tail++].time=q[head].time+1;book[tx][ty][tz]=1;}}head++;}return -1; }int main(){int T;scanf("%d",&T);while(T--){memset(book,0,sizeof(book));memset(map,0,sizeof(map));memset(q,0,sizeof(q));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",&map[i][j][k]);}}printf("%d\n",bfs());}}
0 0
- HDU1253:胜利大逃亡(BFS,三维处理)
- HDU1253 胜利大逃亡 三维BFS
- hdu1253 胜利大逃亡(三维bfs索搜)
- hdu1253 胜利大逃亡(三维bfs)
- 胜利大逃亡hdu1253三维bfs
- 【三维bfs】HDU1253——胜利大逃亡
- HDU1253:胜利大逃亡(BFS)
- hdu1253胜利大逃亡 (BFS)
- HDU1253:胜利大逃亡(BFS)
- HDU1253 胜利大逃亡 BFS
- HDU1253 胜利大逃亡【BFS】
- HDU1253 胜利大逃亡 BFS
- hdu1253胜利大逃亡bfs
- 【BFS】HDU1253胜利大逃亡
- HDU1253:胜利大逃亡(BFS)
- HDU1253 胜利大逃亡(BFS)
- hdu1253胜利大逃亡(bfs)
- HDU1253 胜利大逃亡(BFS)
- 高德地图显示自定义信息窗体
- 334_onTouch和onTouchEvent
- [矩阵快速幂/推函数式]Codeforces185A Plant
- 神奇的程序
- 335_ViewGroup
- 胜利大逃亡hdu1253三维bfs
- LOL因为代理登录失败的问题
- 336_ViewGroup的dispatchTouchEvent
- 如何将span 元素设置成有高度宽度的块元素
- 集合:接口Set
- 红色标重点,蓝色分列表,紫色经验区
- 337_图片轮播器使用button
- Android开发中的动画(下)--属性动画Property Animation
- Caffe 在自己的数据库上训练步骤