HDU - 1253
来源:互联网 发布:传送门骑士游数据错误 编辑:程序博客网 时间:2024/06/05 18:20
HDU - 1253
#include<cstdio>#include<queue>#include<cstring>using namespace std;int a,b,c,t;int mp[57][57][57];struct data{ int x,y,z; int cost; data(){cost=0;} data(int a,int b,int c,int d) { z=a; x=b; y=c; cost=d; }}d[1007];queue<data>que;bool ok(int x,int y,int z){ if(x<0||x>=b||y<0||y>=c||z<0||z>=a||mp[z][x][y]) { return false; } return true;}bool vis[57][57][57];int dx[]={0,1,0,-1,0,0};int dy[]={1,0,-1,0,0,0};int dz[]={0,0,0,0,1,-1};int bfs(){ memset(vis,0,sizeof vis); while(!que.empty()) que.pop();vis[0][0][0]=1; data st=data(0,0,0,0); que.push(st); while(!que.empty()) { data now=que.front(); que.pop(); if(now.z==a-1&&now.x==b-1&&now.y==c-1) { return now.cost; } for(int i=0;i<6;i++) { int zz,xx,yy; xx=now.x+dx[i]; yy=now.y+dy[i]; zz=now.z+dz[i]; if(ok(xx,yy,zz)&&!vis[zz][xx][yy]) { vis[zz][xx][yy]=1; que.push(data(zz,xx,yy,now.cost+1)); } } } return 0x3f3f3f3f;}int main(){ int T; scanf("%d",&T); while(T--) { 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",&mp[i][j][k]); } } }// for(int i=0;i<a;i++)// {// for(int j=0;j<b;j++)// {//// for(int k=0;k<c;k++)// {// printf("%d",mp[i][j][k]);// }// }// puts("");// } int tmp=bfs(); if(tmp>t) { puts("-1"); } else printf("%d\n",tmp); } 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 三维bfs
- HDU 1253(BFS)
- HDU[1253]--bfs
- hdu~1253(bfs)
- hdu 1253 bfs
- hdu 1253 bfs
- 安装Docker管理图形管理工具Shipyard
- MPI Maelstrom poj 1502 单源最短路
- 51nod 1383 整数分解为2的幂
- Oracle Database之集合操作函数(UNION, INTERSECT, MINUS)
- 第十五周项目1-(3)希尔排序
- HDU - 1253
- 某年某天我是否会遇见你
- js/jquery/html前端开发常用到代码片段
- 我的一个c语言程序,践行!
- Android利用productFlavors 打包不同版本API的调用
- 组合数取模
- 蓝桥杯 算法训练 s01串
- 12.03
- 2016 Unicode Conference拾遗(四)