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

    题目  中文题,题意不赘述。

    遇到上下两层都是# 的,就把上下两层的这个位置都弄成墙

    还有遇到 一层是#一层是墙的,也直接把俩都弄城墙就行,省的要判断他撞死。

    mp[][][]开个三维的,记录两层楼

    #include<iostream>
    #include <cstdio>
    #include<queue>
    #include <cstring>
    using namespace std;
    
    struct point{
        int x,y,step,type;
    }P[105];//记录坐标(x,y);步数即时间;一层楼还是二层楼
    
    char mp[2][15][15];
    int N,M,time;
    int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
    /*
        P终点
        #传输机
        *墙
    */
    int bfs(point S)
    {
        point t,tmp;
        queue<point> Q;
        Q.push(S);
        while(!Q.empty())
        {
            t = Q.front();
            Q.pop();
            if(mp[t.type][t.x][t.y]=='*') continue ;//不能走
            if(mp[t.type][t.x][t.y]=='P') return 1;//到达终点
            mp[t.type][t.x][t.y] = '*';//走过的地方标志为墙
            for(int i=0;i<4;i++)
            {
                tmp.x = t.x + dir[i][0];
                tmp.y = t.y + dir[i][1];
                tmp.step = t.step+1;
                tmp.type = t.type;
                if(tmp.step>time||mp[tmp.type][tmp.x][tmp.y]=='*')//P被吃了or走不通
                    continue;
                if(mp[tmp.type][tmp.x][tmp.y]=='#'){
                    mp[tmp.type][tmp.x][tmp.y]='*';
                    tmp.type = 1-tmp.type;//传输到另一层
                    if(mp[tmp.type][tmp.x][tmp.y]=='#'||mp[tmp.type][tmp.x][tmp.y]=='*')
                    {//传输入过去的那个地方是'#' or '*' 就把当前位置设置为墙'*',表示不能走
                        mp[tmp.type][tmp.x][tmp.y]=mp[1-tmp.type][tmp.x][tmp.y]='*';
                        continue;//换个位置
                    }
                }
                Q.push(tmp);
            }
        }
        return 0;
    }
    int main()
    {
        point S;
        int T;cin>>T;
        while(T--)
        {
            cin>>N>>M>>time;
            memset(mp,'*',sizeof(mp));
            for(int i=0;i<N;i++)
                for(int j=0;j<M;j++)
                    cin>>mp[0][i][j];
    
             for(int i=0;i<N;i++)
                for(int j=0;j<M;j++)
                    cin>>mp[1][i][j];
            S.x = 0; S.y = 0; S.step = 0;S.type = 0;
            if(bfs(S)) printf("YES
    ");
            else printf("NO
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    奇数阶魔方问题
    《DSP using MATLAB》示例9.3
    《DSP using MATLAB》示例9.2
    《DSP using MATLAB》示例9.1
    找个目标很重要
    《DSP using MATLAB》示例Example 8.30
    《DSP using MATLAB》示例Example 8.29
    《DSP using MATLAB》示例Example 8.28
    《DSP using MATLAB》示例Example 8.27
    《DSP using MATLAB》示例Example 8.26
  • 原文地址:https://www.cnblogs.com/qie-wei/p/10160130.html
Copyright © 2011-2022 走看看