标签:des style blog http java color 使用 os
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25112 Accepted Submission(s): 9609
#include <stdio.h> #include <string.h> int map[60][60][60]; int vt[60][60][60] ; struct N { int x, y, z; int cnt; }s[210000], e, f; int xx[6]={0, 0, 0, 0, 1, -1}; int yy[6]={0, 0, -1, 1, 0, 0}; int zz[6]={1, -1, 0, 0, 0, 0}; int a, b, c, tt; void bfs() { int i, j=0, k=0 ; int flag = 0; e.x = 0; e.y = 0; e.z = 0; e.cnt = 0; s[k++] = e; vt[0][0][0] =1 ; while(j < k ) { e = s[j++]; if(e.x==a-1 && e.y==b-1 && e.z==c-1 ) { if(e.cnt <= tt) { printf("%d\n", e.cnt ); return ; } else { printf("-1\n"); return ; } } for(i=0; i<6; i++) { f.x = e.x + xx[i]; f.y = e.y + yy[i]; f.z = e.z + zz[i]; if( f.x>=0&&f.x<a &&f.y>=0&&f.y<b && f.z>=0 &&f.z<c&& vt[f.x][f.y][f.z]==0 && map[f.x][f.y][f.z]==1 ) { f.cnt = e.cnt + 1; s[k++] = f; vt[f.x][f.y][f.z]=1; } } } printf("-1\n"); /* if(flag==1 && sum <tt ) { printf("%d\n", sum ); } else { printf("-1\n"); } */ } int main() { int t; int i, j, k,ff; scanf("%d", &t) ; while(t--) { memset(map, 0, sizeof(map )); memset(vt, 0, sizeof(vt )); k = 0; scanf("%d %d %d %d", &a, &b, &c, &tt ); for(i=0; i<a; i++) { for(j=0; j<b; j++) { for(k=0; k<c; k++) { scanf("%d", &ff ); if(ff==1) map[i][j][k] = 0; //memset 为0,避免冲突修改一下,1代表路,0 代表墙 else { map[i][j][k] = 1; } } } } if(map[a-1][b-1][c-1]==0 || a+b+c>tt) //出口处是墙 或者 可能到达出口的最短时间都比妖怪回来的时间长必然逃不了 { printf("-1\n"); continue; } bfs(); } return 0; }
标签:des style blog http java color 使用 os
原文地址:http://www.cnblogs.com/yspworld/p/3875802.html