Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA WA WA niu niu niu

Posted by tjrac6016202273 at 2017-11-09 12:04:14 on Problem 2251
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;

char mmp[50][50][50];
bool vis[50][50][50];
int l,r,c;
int sx,sy,sz,ex,ey,ez;
int dx[6]={-1,1,0,0,0,0};
int dy[6]={0,0,1,-1,0,0};
int dz[6]={0,0,0,0,1,-1};
struct node
{
    int x,y,z,step;
};

bool check(int x,int y,int z)
{
    if(x>=l||y>=r||z>=c||x<0||y<0||z<0||mmp[x][y][z]=='#'||vis[x][y][z]==1) return true;
    return false;
}

int bfs()
{
    node now,next;
    queue<node>Q;
    while(!Q.empty()) Q.pop();
    now.x=sx,now.y=sy,now.z=sz,now.step=0;
    vis[now.x][now.y][now.z]=1;
    Q.push(now);
    while(!Q.empty())
    {
        now=Q.front();
        Q.pop();
        if(now.x==ex&&now.y==ey&&now.z==ez) return now.step;
        for(int i=0;i<6;i++)
        {
            next.x=now.x+dx[i];
            next.y=now.y+dy[i];
            next.z=now.z+dz[i];
            if(check(next.x,next.y,next.z)) continue;
            vis[next.x][next.y][next.z]=1;
            next.step=now.step+1;
            Q.push(next);
        }
    }
    return 0;
}

int main ()
{
    while(scanf("%d %d %d",&l,&r,&c))
    {
        if(!l&&!r&&!c) break;
        getchar();
        for(int i=0;i<l;i++)
        {
            for(int j=0;j<r;j++)
            {
                scanf("%s",mmp[i][j]);
                for(int k=0;k<c;k++)
                {
                    if(mmp[i][j][k]=='S'){sx=i,sy=j,sy=k;}
                    else if(mmp[i][j][k]=='E'){ex=i,ey=j,ez=k;}
                }
            }
        }
        memset(vis,0,sizeof(vis));
        int ans=bfs();
        if(ans) printf("Escaped in %d minute(s).\n",ans);
        else printf("Trapped!\n");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator