Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
跪求帮忙的垃圾#include <iostream> #include <cstdio> #include <cstring> using namespace std; int limit[31][31][31]; int vis[31][31][31]; int a,b,c,ans,si,sj,sk,bi,bj,bk; char chr; void dfs(int i, int j, int k ) {if(vis[bi][bj][bk]==1) { ans=limit[bi][bj][bk]<ans?limit[bi][bj][bk]:ans; vis[bi][bj][bk]=0; } if(i>0&&vis[i-1][j][k]==0) { vis[i-1][j][k]=1; limit[i-1][j][k]=limit[i][j][k]+1; dfs(i-1,j,k); } if(j>0&&vis[i][j-1][k]==0) { vis[i][j-1][k]=1; limit[i][j-1][k]=limit[i][j][k]+1; dfs(i,j-1,k); } if(k>0&&vis[i][j][k-1]==0) { vis[i][j][k-1]=1; limit[i][j][k-1]=limit[i][j][k]+1; dfs(i,j,k-1); } if(i<a-1&&vis[i+1][j][k]==0) { vis[i+1][j][k]=1; limit[i+1][j][k]=limit[i][j][k]+1; dfs(i+1,j,k); } if(j<b-1&&vis[i][j+1][k]==0) { vis[i][j+1][k]=1; limit[i][j+1][k]=limit[i][j][k]+1; dfs(i,j+1,k); } if(k<c-1&&vis[i][j][k+1]==0) { vis[i][j][k+1]=1; limit[i][j][k+1]=limit[i][j][k]+1; dfs(i,j,k+1); } } int main() { while(~scanf("%d%d%d",&a,&b,&c)&&a!=0&&b!=0&&c!=0) { for(int i=0;i<a;i++) for(int j=0;j<b;j++) for(int k=0;k<c;k++) vis[i][j][k]=0; ans=1e9; getchar(); for(int i=0;i<a;i++) { for(int j=0;j<b;j++) { for(int k=0;k<c;k++) { scanf("%c",&chr); if(chr=='S') { si=i; sj=j; sk=k; limit[i][j][k]=0; vis[i][j][k]=1; } else if(chr=='#') { limit[i][j][k]=-1; vis[i][j][k]=-1; } else if(chr=='E') { limit[i][j][k]=0; bi=i; bj=j; bk=k; } else { limit[i][j][k]=0; } }getchar(); } getchar(); } dfs(si,sj,sk); if(limit[bi][bj][bk]==0) cout<<"Trapped!"<<endl; else cout<<"Escaped in "<<ans<<" minute(s)."<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator