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

bfs 水题,好奇那些16s和0s的大牛是怎么写的

Posted by sunkangju at 2017-12-14 19:48:23 on Problem 2251
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
char mapp[35][35][35];
struct node{
    int x,y,z,step;
}e,rr;
int dir[6][3]={
0,1,0,
0,-1,0,
0,0,1,
0,0,-1,
1,0,0,
-1,0,0
};
int vis[35][35][35];
queue<node>qu;
int main(){
    int l,r,c,i,j,k;
    while(~scanf("%d%d%d",&l,&r,&c),l+r+c){
        memset(vis,0,sizeof(vis));
        while(!qu.empty())qu.pop();
        for(i=0;i<l;i++){
            getchar();
            for(j=0;j<r;j++){
                for(k=0;k<c;k++){
                    scanf("%c",&mapp[i][j][k]);
                    if(mapp[i][j][k]=='S'){
                        e.x=i;
                        e.y=j;
                        e.z=k;
                        e.step=0;
                        qu.push(e);
                    }
                }
                getchar();
            }
        }
        while(!qu.empty()){
            e=qu.front();
            qu.pop();
            rr.step=e.step+1;
            for(i=0;i<6;i++){
                rr.x=e.x+dir[i][0];
                rr.y=e.y+dir[i][1];
                rr.z=e.z+dir[i][2];
                if(0<=rr.x&&rr.x<l&&0<=rr.y&&rr.y<r&&0<=rr.z&&rr.z<c&&vis[rr.x][rr.y][rr.z]==0&&mapp[rr.x][rr.y][rr.z]!='#'){
                    if(mapp[rr.x][rr.y][rr.z]=='E'){
                        printf("Escaped in %d minute(s).\n",rr.step);
                        goto l1;
                    }
                    qu.push(rr);
                    vis[rr.x][rr.y][rr.z]=1;
                }
            }
        }
        printf("Trapped!\n");
        l1:;
    }
    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