HDU 2102 A计划 (超简单三维dfs)

本来以为进阶搜索会有难一点的剪枝,没想到这个这么水。。

https://vjudge.net/problem/HDU-2102

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int n, m, t;
char a[3][15][15];
bool vis[3][15][15];
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
struct node
{
    int x, y, z, t;
};
bool bfs(int z, int x, int y)
{
    queue<node> q;
    node h, next;
    h.x = x, h.y = y, h.z = z;
    h.t = 0;
    q.push(h);
    vis[z][x][y] = 1;
    //int miny = inf;
    while(! q.empty())
    {
        h = q.front();
        q.pop();
        if(h.t > t) return 0;
        for(int i = 0; i < 4; i ++)
        {
            int u = h.x + dir[i][0];
            int v = h.y + dir[i][1];
            int p = h.z;
            if(u >= 1 && u <= n && v >= 1 && v <= m && ! vis[p][u][v] && a[p][u][v] != '*')
            {
                if(a[p][u][v] == 'P')
                {
                    return (h.t + 1 <= t);
                }
                else if(a[p][u][v] == '#')
                {
                    p += 1;
                    if(p > 2) p -= 2;
                    if(a[p][u][v] == '*' || a[p][u][v] == '#')
                    {
                        vis[p][u][v] = 1;
                        continue;
                    }
                    else if(a[p][u][v] == 'P') return (h.t + 1 <= t);
                    else
                    {
                        vis[p][u][v] = 1;
                        next.z = p, next.x = u, next.y = v;
                        next.t = h.t + 1;
                        q.push(next);
                        //miny = min(miny, next.t);
                    }
                }
                else
                {
                    vis[p][u][v] = 1;
                    next.z = p, next.x = u, next.y = v;
                    next.t = h.t + 1;
                    q.push(next);
                    //miny = min(next.t, miny);
                }
            }
        }
        //if(miny > t) return 0;
    }
    return 0;
}
int main()
{
    int T;
    scanf("%d", &T);
    while(T --)
    {
        scanf("%d%d%d" ,&n, &m, &t);
        for(int k = 1; k <= 2; k ++)
            for(int i = 1; i <= n; i ++)
                //for(int j = 1; j <= m; j ++)
                scanf("%s", a[k][i] + 1);
        memset(vis, 0, sizeof(vis));
        if(bfs(1, 1, 1)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值