zoukankan      html  css  js  c++  java
  • [POJ

    还是迷宫只是从之前的二维变成了三维而已。

    #include <cstring>
    #include <cstdio>
    #include <queue>
    #include <iostream>
    using namespace std;
    
    struct test
    {
        int x,y,z;
        int step;
    };
    
    int direction[6][3]={1,0,0, 0,1,0, 0,0,1, -1,0,0, 0,-1,0, 0,0,-1};
    int main()
    {
        int xi, yi, zi;
        queue<test> q;
        
        test temp, start, end;
        while(~scanf("%d%d%d", &zi,&yi,&xi) && zi+yi+xi)
        {
          while(!q.empty())
            q.pop(); 
        char s[31][31][31];
        int vis[31][31][31];
        
        memset(vis, 0, sizeof(vis));
        
        for(int i = 0;i < zi;i++)
            for(int j = 0; j< yi;j++)
                for(int k = 0; k<xi;k++)
                    {
                        cin>>s[i][j][k];
                        if(s[i][j][k] == 'S')
                            {
                                start.x = k;
                                start.y = j;
                                start.z = i;
                            }
                        else if(s[i][j][k] == 'E')
                            {
                                end.x = k;
                                end.y = j;
                                end.z = i;    
                            }
                    }
    //    printf("start: %d %d %d
    end: %d %d %d", start.z, start.y, start.x, end.z, end.y, end.x);
        start.step = 0;            
        q.push(start);
        vis[start.z][start.y][start.x] = 1;
        int ans = 0;
        while(!q.empty())
        {
            start = q.front();
            if(start.z == end.z && start.x == end.x && start.y == end.y) 
            {ans = start.step; 
            break;
        }
            q.pop();
            for(int i = 0; i< 6; i++)
            {
                temp.z = start.z + direction[i][0];
                temp.y = start.y + direction[i][1];
                temp.x = start.x + direction[i][2];
                if(temp.x <xi&&temp.x>=0&&temp.y <yi&&temp.y>=0&&temp.z>=0&&temp.z<zi&&!vis[temp.z][temp.y][temp.x]&&s[temp.z][temp.y][temp.x] != '#')
                    {
                        
                        temp.step = start.step+1;
                    //    printf("temp: %d %d %d %d
    ", temp.z, temp.y, temp.x, start.step);
                        q.push(temp);
                        vis[temp.z][temp.y][temp.x] = 1;
                    }
            }
        }
        
        if(ans)
            printf("Escaped in %d minute(s).
    ", ans);
        else
            printf("Trapped!
    ");
             
        
    }
        return 0;
     } 
  • 相关阅读:
    docker 入门(docker 镜像 、容器、仓库)
    windows 安装 docker
    关于go mod 的使用和goland 配置 go mod
    mac 安装docker
    vm 将宿主机文件夹 映射至 虚拟机
    centos 关于yum无法使用
    mac 安装 swoole 可能会出现的错误
    BZOJ3378:[USACO]MooFest 狂欢节(树状数组)
    BZOJ3110:[ZJOI2013]K大数查询(整体二分)
    BZOJ4170:极光(CDQ分治)
  • 原文地址:https://www.cnblogs.com/Vikyanite/p/11382465.html
Copyright © 2011-2022 走看看