zoukankan      html  css  js  c++  java
  • hdu 2102 A计划(bfs)

    之前没有考虑到 两层都是 # 的情况 

    #include<cstdio>
    #include<cmath>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #define mem(a,b) memset(a,b,sizeof(a))
    using namespace std;
    int n,m,coun,ok1;
    char mat[5][20][20];
    int op[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
    struct node{
      int t;
      int w,x,y;
    };
    
    bool ok(node next)
    {
        if(next.x<0||next.x>=n||next.y<0||next.y>=m) return false;   
        if(mat[next.w][next.x][next.y]=='S'||mat[next.w][next.x][next.y]=='*') return false;
        return true;
    }
    void bfs()
    {
        queue<node> q;
        node now,next;
        now.t=0;
        now.w=0;
        now.x=0;
        now.y=0;
        q.push(now);
        while(!q.empty())
        {
            now=q.front();
            q.pop();
            if(now.t>=coun) return;
    
            for(int i=0;i<4;i++)
            {
                next.x=now.x+op[i][0];
                next.y=now.y+op[i][1];
                next.w=now.w;
                if(ok(next))
                {
                    next.t=now.t+1;
                    if(mat[now.w][next.x][next.y]=='#') {next.w=1-now.w;}
                    if(!ok(next)) continue;
                if(mat[next.w][next.x][next.y]=='P')
                {
                    ok1=1;
                    return ;
                }            
                if(mat[next.w][next.x][next.y]=='.')
                {
                    mat[next.w][next.x][next.y]='S';
                    q.push(next);
                }            
                }            
            }
        }
    }
    int main()
    {
        int i,t;
        cin>>t;
        while(t--)
        {
            ok1=0;
            scanf("%d%d%d",&n,&m,&coun);
            memset(mat,0,sizeof(mat));
            for(i=0;i<n;i++)
            {
                scanf("%s",mat[0][i]);
            }
            for(i=0;i<n;i++)
            {
                scanf("%s",mat[1][i]);
            }
            bfs();
            if(ok1)
                printf("YES
    ");
            else printf("NO
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    ifdef有大用处
    osgEarth编译
    CyanogenMod 7.1 for Sony Ericsson X8 下载 CM7.1 for 索爱X8下载
    ArcGIS影像配准与空间配准
    ArcGIS Server的切图原理深入
    Arcgis server的rest服务url写法解读
    地图切片公式
    新随笔
    solr的java调用
    配置文件
  • 原文地址:https://www.cnblogs.com/sola1994/p/4296705.html
Copyright © 2011-2022 走看看