HDU 2102 A计划

 

A计划

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 28671    Accepted Submission(s): 7204


Problem Description
可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。
现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。
 


Input
输入的第一行C表示共有C个测试数据,每个测试数据的前一行有三个整数N,M,T。 N,M迷宫的大小N*M(1 <= N,M <=10)。T如上所意。接下去的前N*M表示迷宫的第一层的布置情况,后N*M表示迷宫第二层的布置情况。
 


Output
如果骑士们能够在T时刻能找到公主就输出“YES”,否则输出“NO”。
 


Sample Input
 
 
 
样例拉不过来,贴在代码中
 
Sample Output
YES

 

挺简单的一道 bfs ,之前老是超时。。。后来才发现交错题号了。。。

主要是刚开始把图处理一下,过程能少判断很多

当 # 对应过去还是 # ,就把这两个地方都变成 * ,当 # 对应过去是 * ,同样处理

  1 #include <iostream>
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <cmath>
  5 #include <iomanip>
  6 #include <string>
  7 #include <sstream>
  8 #include <algorithm>
  9 #include <stack>
 10 #include <queue>
 11 #include <set>
 12 #include <map>
 13 
 14 using namespace std;
 15 
 16 typedef long long LL;
 17 const int INF = 0x3f3f3f3f;
 18 const int MAXN = 1000005;
 19 const int MOD = 1e9 + 7;
 20 
 21 #define MemI(x) memset(x, -1, sizeof(x))
 22 #define Mem0(x) memset(x, 0, sizeof(x))
 23 #define MemM(x) memset(x, 0x3f, sizeof(x));
 24 
 25 char mp[3][25][25];
 26 int vis[3][25][25];
 27 struct Node
 28 {
 29     int x, y, z;
 30     int step;
 31 }t;
 32 queue<Node> q;
 33 int n, m, num, dis[][2] = {0, 1, 0, -1, -1, 0, 1, 0};
 34 
 35 bool solve()
 36 {
 37     int i, j, k, x, y, z, step;
 38     while(!q.empty())
 39     {
 40         x = q.front().x, y = q.front().y, z = q.front().z, step = q.front().step;
 41         q.pop();
 42         if(mp[z][x][y] == 'P')
 43         {
 44 //            cout << step << endl;
 45             if(step <= num)
 46                 return true;
 47             return false;
 48         }
 49         if(vis[z][x][y])
 50             continue;
 51         vis[z][x][y] = 1;
 52         for(k = 0;k < 4;++k)
 53         {
 54             i = x + dis[k][0];
 55             j = y + dis[k][1];
 56             if(i < 0 || j < 0 || i >= n || j >= m || mp[z][i][j] == '*')
 57                 continue;
 58             t.z = z;
 59             if(mp[z][i][j] == '#')
 60             {
 61                 vis[z][i][j] = 1;
 62                 t.z = !z;
 63             }
 64             t.x = i, t.y = j, t.step = step + 1;
 65 //            cout << t.z << " " << t.x << " " << t.y << " " << t.step << endl;
 66             q.push(t);
 67         }
 68     }
 69     return false;
 70 }
 71 
 72 int main()
 73 {
 74     int T;
 75     cin >> T;
 76     while(T--)
 77     {
 78         while(!q.empty())
 79             q.pop();
 80         Mem0(vis);
 81         cin >> n >> m >> num;
 82         for(int i = 0;i < n;++i)
 83         {
 84             getchar();
 85             for(int j = 0;j < m;++j)
 86                 cin >> mp[0][i][j];
 87         }
 88         for(int i = 0;i < n;++i)
 89         {
 90             getchar();
 91             for(int j = 0;j < m;++j)
 92             {
 93                 cin >> mp[1][i][j];
 94                 if(mp[0][i][j] == '#')
 95                     if(mp[1][i][j] == '#' || mp[1][i][j] == '*')
 96                     mp[0][i][j] = mp[1][i][j] = '*';
 97             }
 98         }
 99         t.x = 0, t.y = 0, t.z = 0, t.step = 0;
100         q.push(t);
101         if(solve())
102             cout << "YES" << endl;
103         else
104             cout << "NO" << endl;
105     }
106     return 0;
107 }
108 /*
109 1
110 5 5 14
111 S*#*.
112 .#...
113 .....
114 ****.
115 ...#.
116 
117 ..*.P
118 #.*..
119 ***..
120 ...*.
121 *.#..
122 */

 

转载于:https://www.cnblogs.com/shuizhidao/p/9349202.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值