| ||||||||||
| 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 | |||||||||
Re:为什么一直内存超出限制。。。。。。。。求大神解答In Reply To:为什么一直内存超出限制。。。。。。。。求大神解答 Posted by:Jenius at 2018-11-25 12:41:26 > #include<iostream>
> #include<cstring>
> #include<cstdio>
> #include<queue>
> using namespace std;
> struct Node{
> int x,y,z,num;
> Node(int zz = 0,int xx = 0,int yy = 0,int step = 0) : z(zz),x(xx),y(yy),num(step){}
> };
> char t,mp[35][35][35];
> int l,r,c,t1,t2,t3,ans,next[6][3] = {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
> int bfs(int z,int x,int y){
> Node p;
> int vis[35][35][35];
> memset(vis,0,sizeof(vis));
> queue <Node> Q;
> vis[z][x][y] = true;
> Q.push(Node(z,x,y,0));
> while(!Q.empty()){
> p = Q.front();
> Q.pop();
> for(int i = 0;i < 6;i++){
> int tz = p.z + next[i][0];
> int tx = p.x + next[i][1];
> int ty = p.y + next[i][2];
> if(tz < 0 || tz >= l || tx < 0 || tx >= r || ty < 0 || ty >= c)
> continue;
> if(mp[tz][tx][ty] == '.' && vis[tz][tx][ty] == false){
> vis[tz][tx][ty] == true;
> Q.push(Node(tz,tx,ty,p.num + 1));
> }
> if(mp[tz][tx][ty] == 'E'){
> return p.num + 1;
> }
> }
> }
> return 0;
> }
> int main(){
> while(~scanf("%d %d %d",&l,&r,&c)){
> if(!l && !r && !c)
> break;
> for(int i = 0;i < l;i++){
> for(int j = 0;j < r;j++){
> getchar();
> for(int k = 0;k < c;k++){
> scanf("%c",&mp[i][j][k]);
> if(t == 'S')
> t1 = i,t2 = j,t3 = k;
> }
> }
> getchar();
> }
> ans = bfs(t1,t2,t3);
> ans == 0 ? printf("Trapped!\n") : printf("Escaped in %d minute(s).\n",ans);
> }
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator