zoukankan      html  css  js  c++  java
  • HDU 2102 A计划

    水bfs。

    仅仅须要推断一下 #之后还是*或#都是死路。

    仅仅有两层。

    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<map>
    #include<stack>
    #include<iostream>
    #include<list>
    #include<set>
    #include<vector>
    #include<cmath>
    
    #define INF 0x7fffffff
    #define eps 1e-8
    #define LL long long
    #define PI 3.141592654
    #define CLR(a,b) memset(a,b,sizeof(a))
    #define FOR(i,a,n) for(int i= a;i< n ;i++)
    #define FOR0(i,a,b) for(int i=a;i>=b;i--)
    #define pb push_back
    #define mp make_pair
    #define ft first
    #define sd second
    #define acfun std::ios::sync_with_stdio(false)
    
    #define SIZE 10+1
    using namespace std;
    
    struct lx
    {
        int x,y,z,t;
        void init(int xx,int yy,int zz,int tt)
        {
            x=xx,y=yy,z=zz,t=tt;
        }
    
    }thend,start;
    
    char g[2][SIZE][SIZE];
    int n,m;
    int xx[]={0,0,-1,1};
    int yy[]={-1,1,0,0};
    
    void bfs()
    {
        bool vis[2][SIZE][SIZE];
        CLR(vis,0);
        queue<lx>q;
        q.push(start);
        vis[0][0][0]=1;
        while(!q.empty())
        {
            lx tmp=q.front();
            q.pop();
            //printf("%d %d %d t=%d
    ",tmp.x,tmp.y,tmp.z,tmp.t);
            //system("pause");
            if(tmp.t>thend.t)continue;
            if(tmp.x==thend.x&&tmp.y==thend.y&&tmp.z==thend.z&&tmp.t<=thend.t)
            {
                puts("YES");
                return;
            }
            FOR(k,0,4)
            {
                int x=tmp.x+xx[k];
                int y=tmp.y+yy[k];
                int z=tmp.z;
                lx now;
                if(x<0||y<0||x>=n||y>=m||g[z][x][y]=='*'||vis[z][x][y])continue;
                vis[z][x][y]=1;
                if(g[z][x][y]=='#')
                {
                    z^=1;
                    if(g[z][x][y]=='*'||g[z][x][y]=='#')continue;
                }
                now.init(x,y,z,tmp.t+1);
                q.push(now);
    
            }
        }
        puts("NO");
    }
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int tt;
            scanf("%d%d%d",&n,&m,&tt);
            FOR(k,0,2)
            FOR(i,0,n)
            {
                char str[SIZE];
                scanf("%s",str);
                FOR(j,0,m)
                {
                    g[k][i][j]=str[j];
                    if(str[j]=='P')
                        thend.init(i,j,k,tt);
                }
            }
            start.init(0,0,0,0);
            bfs();
        }
    }
    


  • 相关阅读:
    python基础—函数装饰器
    python基础—函数嵌套与闭包
    Python之三级菜单
    Python之运算符
    Python之字典
    Python之购物车
    Python之列表
    Python之布尔
    Python之“Hello World”
    Python之递归函数
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7350508.html
Copyright © 2011-2022 走看看