当前位置: 移动技术网 > IT编程>开发语言>C/C++ > I - A计划 HDU - 2102

I - A计划 HDU - 2102

2020年07月17日  | 移动技术网IT编程  | 我要评论

HDU - 2102

思路:
水题一个,暴力BFS就能过,注意判断魔法阵对面是否还是传送阵

代码附:

#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
using namespace std;
const int N = 2e5+10;
int n,m,t;
char mp[2][11][11];
int vis[2][11][11];
int X[4]= {1,-1,0,0};
int Y[4]= {0,0,1,-1};
struct node
{
    int x,y,z,step;
};
bool check(node k)
{
    if(k.x<0||k.x==n||k.y<0||k.y==m||k.step>t||vis[k.z][k.x][k.y]&&vis[k.z][k.x][k.y]<k.step||mp[k.z][k.x][k.y]=='*'||mp[k.z][k.x][k.y]=='#'&&(mp[k.z^1][k.x][k.y]=='#'||mp[k.z^1][k.x][k.y]=='*'))
        return true;
    return false;
}
bool bfs()
{
    node k;
    k.x=0,k.y=0,k.z=0,k.step=0;
    queue<node>qq;
    qq.push(k);
    while(qq.size())
    {
        k=qq.front();
        qq.pop();
        if(mp[k.z][k.x][k.y]=='P')
            return true;
        for(int i=0; i<4; ++i)
        {
            node kk=k;
            kk.x+=X[i],kk.y+=Y[i],kk.step++;
            if(check(kk))
                continue;
            vis[kk.z][kk.x][kk.y]=kk.step;
            if(mp[kk.z][kk.x][kk.y]=='#')
                kk.z^=1;
            if(check(kk))
                continue;
            vis[kk.z][kk.x][kk.y]=kk.step;
            qq.push(kk);
        }
    }
    return false;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>t;
        for(int p=0; p<2; ++p)
            for(int i=0; i<n; ++i)
                cin>>mp[p][i];
        memset(vis,0,sizeof(vis));
        vis[0][0][0]=1;
        if(bfs())
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

本文地址:https://blog.csdn.net/qq_43586463/article/details/107379113

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网