标签:iss line 使用 alt main pac step blank enter
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1253
胜利大逃亡
Time Limit:4000/2000MS(Java/Others)Memory Limit:65536/32768K(Java/Other)
Total Submission(s): 37822 Accepted Submission(s): 13320
1 #include<stdio.h> 2 #include<string.h> 3 #include<queue> 4 using namespace std; 5 #define MAXX 80 6 int dd[MAXX][MAXX][MAXX],sum; 7 int x[6]={1,-1,0,0,0,0}; 8 int y[6]={0,0,1,-1,0,0}; 9 int z[6]={0,0,0,0,1,-1}; 10 int a,b,c,n,t,i,j,k; 11 struct A{ 12 int xx,yy,zz,step; 13 }; 14 int pan(int e,int f,int g) 15 { 16 if(e<0||f<0||g<0||e>=a||f>=b||g>=c||dd[e][f][g]==1) 17 return 1; 18 return 0; 19 } 20 int bfs(int e,int f,int g) 21 { 22 int o; 23 queue<A > q; 24 A qq,qqq; 25 qq.xx=e; 26 qq.yy=f; 27 qq.zz=g; 28 qq.step=0; 29 dd[e][f][g]=1; 30 q.push(qq); 31 while(!q.empty()) 32 { 33 qq=q.front(); 34 q.pop(); 35 if(qq.xx==a-1&&qq.yy==b-1&&qq.zz==c-1&&qqq.step<=n) 36 return qq.step; 37 for(o=0;o<6;o++) 38 { 39 qqq=qq; 40 qqq.xx+=x[o]; 41 qqq.yy+=y[o]; 42 qqq.zz+=z[o]; 43 if(!dd[qqq.xx][qqq.yy][qqq.zz]&&!pan(qqq.xx,qqq.yy,qqq.zz)) 44 { 45 qqq.step++; 46 q.push(qqq); 47 dd[qqq.xx][qqq.yy][qqq.zz]=1; 48 } 49 } 50 } 51 return -1; 52 53 } 54 int main() 55 { 56 57 scanf("%d",&t); 58 while(t--) 59 { 60 memset(dd,0,sizeof(dd)); 61 scanf("%d%d%d%d",&a,&b,&c,&n); 62 for(i=0;i<a;i++) 63 { 64 for(j=0;j<b;j++) 65 { 66 for(k=0;k<c;k++) 67 { 68 scanf("%d",&dd[i][j][k]); 69 } 70 } 71 } 72 73 sum=bfs(0,0,0); 74 printf("%d\n",sum); 75 } 76 return 0; 77 }
标签:iss line 使用 alt main pac step blank enter
原文地址:http://www.cnblogs.com/ljmzzyk/p/6917938.html