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

    A计划

    分析:

    1. 特殊处理传输机:如果另一层迷宫是墙 / 传输机。
    2. 记录层数,x,y,和时间。
    3. 采用结构体储存队列一个结点内的所有东西。
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<queue>
     5 using namespace std;
     6 
     7 struct node{
     8     int x, y, k, step;
     9 };
    10 int n, m, t;
    11 int dis[4][2]={0,1,1,0,0,-1,-1,0};
    12 bool vis[2][15][25], flag;
    13 char ma[2][15][15];
    14 
    15 void bfs(int x, int y, int k)
    16 {
    17     memset(vis,0,sizeof(vis));
    18     queue<node> Q;
    19     node pre, lst;   //pre当前 lst下一步 
    20 
    21     //类似初始化的东西!
    22     pre.x = x;
    23     pre.y = y;
    24     pre.k = k;
    25     pre.step = 0;
    26     vis[pre.k][pre.x][pre.y] = 1;
    27     Q.push(pre);
    28     
    29     while(!Q.empty()){
    30         pre = Q.front();
    31         Q.pop();
    32         
    33         //找到了
    34         if(ma[pre.k][pre.x][pre.y] == 'P' && pre.step <= t) {flag = true; return;}
    35         //四个方向找公主
    36         for(int i = 0; i < 4; i++){
    37             lst.x = pre.x + dis[i][0];
    38             lst.y = pre.y + dis[i][1];
    39             lst.step = pre.step + 1;
    40             
    41             if(lst.step > t) continue;
    42             if(lst.x < 0 || lst.y < 0 || lst.x >=n || lst.y >= m) continue;
    43             if(ma[pre.k][lst.x][lst.y] == '*' || vis[pre.k][lst.x][lst.y] == 1) continue;
    44             if(ma[pre.k][lst.x][lst.y] == '#'){
    45                 if(pre.k == 1) lst.k = 0;
    46                 if(pre.k == 0) lst.k = 1;
    47                 vis[pre.k][lst.x][lst.y] = 1;
    48                 Q.push(lst);
    49                 continue;
    50             }
    51             vis[pre.k][lst.x][lst.y] = 1;
    52             lst.k = pre.k;
    53             Q.push(lst);
    54         }
    55     }
    56 }
    57 int main()
    58 {
    59     int T;
    60     cin >> T; 
    61     while(T--){
    62         cin >> n >> m >> t;
    63         for(int k = 0; k < 2; k++)
    64             for(int i = 0; i < n; i++)
    65                 for(int j = 0; j < m; j++)
    66                     cin >> ma[k][i][j];
    67         
    68         for(int i = 0; i < n; i++){
    69             for(int j = 0; j < m; j++){
    70                 if(ma[0][i][j] == '#')
    71                     if(ma[1][i][j] == '*' || ma[1][i][j] == '#')
    72                         ma[0][i][j] = ma[1][i][j] = '*';
    73                 if(ma[1][i][j] == '#')
    74                     if(ma[0][i][j] == '*' || ma[0][i][j] == '#')
    75                         ma[0][i][j] = ma[1][i][j] = '*';
    76             }
    77         } 
    78         flag = false;
    79         bfs(0,0,0);
    80         if(flag) cout << "YES" << endl;
    81         else cout << "NO" << endl;
    82     }
    83     return 0;
    84 }
  • 相关阅读:
    jQuery之Ajax应用
    ELK安装配置简单使用
    saltstack其他运行模式
    saltstack syndic安装配置使用
    salt api
    saltstack api安装使用
    saltstack master minion安装配置简单使用
    zabbix api
    zabbix snmp、jmx配置使用
    phoenix安装
  • 原文地址:https://www.cnblogs.com/JiaaaaKe/p/9531036.html
Copyright © 2011-2022 走看看