HDU 2102 A计划

简单三维BFS,需要注意的就是如果传送门进去的下一层还是传送门,则不可以进入。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <iomanip>
#define PI acos(-1.0)
#define Max 2005
#define inf 1<<28
#define LL(x) (x<<1)
#define RR(x) (x<<1|1)
#define FOR(i,s,t) for(int i=(s);i<=(t);++i)
#define ll long long
using namespace std;

int n,m,t;
char Map[2][20][20];

struct kdq
{
    int x,y,z,step;
} q[1000000];

int movex[4]= {0,0,1,-1};
int movey[4]= {1,-1,0,0};
int inmap(kdq a)
{
    if(a.x>=0&&a.x<n&&a.y>=0&&a.y<m&&a.z>=0&&a.z<=1&&Map[a.z][a.x][a.y]!='*')
        return 1;
    return 0;
}
int visit[2][20][20];
int bfs()
{
    kdq s;
    s.x=0,s.y=0,s.z=0,s.step=0;
    int num=0,cnt=0;
    q[num++]=s;
    visit[0][0][0]=1;
    while(num>cnt)
    {
        kdq temp=q[cnt++];
        if(Map[temp.z][temp.x][temp.y]=='P')
        {
            if(temp.step<=t)
                return 1;
            return 0;
        }
        for(int i=0; i<4; i++)
        {
            kdq tt;
            tt=temp;
            tt.x+=movex[i];
            tt.y+=movey[i];
            tt.step++;
            if(inmap(tt))
            {
                if(Map[tt.z][tt.x][tt.y]=='#')//传送门这里稍微注意一下
                {
                   tt.z^=1;
                    if(Map[tt.z][tt.x][tt.y]=='*'||Map[tt.z][tt.x][tt.y]=='#')
                        continue;
                }
                if(!visit[tt.z][tt.x][tt.y])
                {
                    visit[tt.z][tt.x][tt.y]=1;
                    q[num++]=tt;
                }
            }
        }
    }
    return 0;
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&t);
        for(int i=0; i<2; i++)
        {
            for(int j=0; j<n; j++)
            {
                for(int k=0; k<m; k++)
                {
                    visit[i][j][k]=0;
                    cin>>Map[i][j][k];
                }
            }
        }
        if(bfs())
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值