1 3 3 4 20 0 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 0 0 1 1 0 0 1 1 0
11
#include#include #include using namespace std; typedef struct node { int x,y,z; int time; }Node; int X,Y,Z,T,map[55][55][55],Time; int dir[6][3]={{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,-1},{0,0,1}}; void BFS(int x,int y,int z) { Node s,q; queue Q; int e; map[z][y][x]=1; s.x=x; s.y=y; s.z=z; s.time=0; if(s.x==X-1&&s.y==Y-1&&s.z==Z-1&&s.time<=T) { Time=s.time; return ; } Q.push(s); while(!Q.empty()) { q=Q.front(); Q.pop(); for(e=0;e<6;e++) if(dir[e][0]+q.x>=0&&dir[e][0]+q.x =0&&dir[e][1]+q.y =0&&dir[e][2]+q.z T-s.time) { map[s.z][s.y][s.x]=1; continue ; } map[s.z][s.y][s.x]=1; Q.push(s); } } } int main() { int i,j,e,t; scanf(%d,&t); while(t--) { scanf(%d %d %d %d,&Z,&Y,&X,&T); for(e=0;e T||map[Z-1][Y-1][X-1]==1) { printf(-1 ); continue; } Time=-1; BFS(0,0,0); printf(%d ,Time); } return 0; }