zoukankan      html  css  js  c++  java
  • hdu 1253 胜利大逃亡 队列

    /* ***********************************************
    Author        :xryz
    Email         :523689985@qq.com
    Created Time  :2015/4/9 19:45:38
    File Name     :C:UsersAdministratorDesktopa.cpp
    ************************************************ */
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    struct node
    {
        int x,y,z,t;
    }m,m0;
    
    int a,b,c,tme,vis[55][55][55];
    int dx[6]={0,0,0,0,1,-1};
    int dy[6]={0,0,1,-1,0,0};
    int dz[6]={1,-1,0,0,0,0};
    
    int bfs()
    {
        queue<node>q;
        m.x=1,m.y=1,m.z=1,m.t=0;
        q.push(m);
        while(!q.empty())
        {
            m0=q.front();
            q.pop();
            if(m0.t>tme) break;
            if(m0.x==a&&m0.y==b&&m0.z==c) return m0.t;
            m.t=m0.t+1;
            for(int i=0;i<6;i++)
            {
                m.x=m0.x+dx[i];
                m.y=m0.y+dy[i];
                m.z=m0.z+dz[i];
                if(m.x<1||m.x>a||m.y<1||m.y>b||m.z<1||m.z>c||vis[m.x][m.y][m.z]) continue;
                q.push(m);
                vis[m.x][m.y][m.z]=1;
            }
        }
        return -1;
    }
    int main()
    {
        int i,j,k,cas;
        scanf("%d",&cas);
        while(cas--)
        {
            scanf("%d%d%d%d",&a,&b,&c,&tme);
            for(i=1;i<=a;i++)
                for(j=1;j<=b;j++)
                    for(k=1;k<=c;k++)
                        scanf("%d",&vis[i][j][k]);
            printf("%d
    ",bfs());
        }
        return 0;
    }
    
    

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    备忘录模式(java)
    06
    观察者模式(java)
    迭代器模式(c++)
    06
    07
    2021.11.21(迭代器模式c++)
    2021.11.24(状态模式java)
    2021.11.22(hive安装)
    2021.11.23(MYSQL安装)
  • 原文地址:https://www.cnblogs.com/xryz/p/4848045.html
Copyright © 2011-2022 走看看