题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=2102

思路

题目有两个坑点

0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要在T时刻或者T时刻之前找到就可以了

1.如果传输机另一边 是 墙 那么就会被撞死 那如果另一边也是传输机 那么也是就会传来传去 也是行不通的

解决方法 如果 传输机另一边是墙 那么就把这个传输机设置为墙

如果传输机另一边也是传输机 那就把 这两个传输机都设置为墙

因为传输的时候是不需要花费时间的 所以假如我们当前的状态是在传输机上 我们只需要更改一下 楼层就可以了

然后就是BFS 了

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a, b) memset(a, (b), sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-8; const int INF = 0x3f3f3f3f;
const int maxn = 3e1 + 5;
const int MOD = 1e9 + 7; int n, m, t; int Move[4][2]
{
-1, 0,
1, 0,
0,-1,
0, 1,
}; string G[2][15];
int v[2][15][15]; int ans; int scur, sx, sy, ecur, ex, ey; struct node
{
int x, y, cur;
int step;
}; bool ok(int cur, int x, int y)
{
if (x < 0 || x >= n || y < 0 || y >= m || G[cur][x][y] == '*')
return false;
return true;
} void bfs()
{
CLR(v, 0);
node tmp;
tmp.cur = scur;
tmp.x = sx;
tmp.y = sy;
tmp.step = 0;
v[tmp.cur][tmp.x][tmp.y] = 1;
queue <node> q;
q.push(tmp);
while (!q.empty())
{
node u = q.front(), V;
q.pop();
if (u.x == ex && u.y == ey && u.cur == ecur)
{
if (u.step <= t)
ans = 1;
return;
}
if (u.step > t)
return;
for (int i = 0; i < 4; i++)
{
V.cur = u.cur;
V.x = u.x + Move[i][0];
V.y = u.y + Move[i][1];
V.step = u.step + 1;
if (ok(V.cur, V.x, V.y))
{
if (G[V.cur][V.x][V.y] == '#')
V.cur = !V.cur;
if (v[V.cur][V.x][V.y] == 0)
q.push(V);
v[V.cur][V.x][V.y] = 1;
}
}
}
} int main()
{
int T;
cin >> T;
while (T--)
{
scanf("%d%d%d", &n, &m, &t);
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < n; j++)
cin >> G[i][j];
}
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < m; k++)
{
if (G[i][j][k] == '#')
{
if (G[!i][j][k] == '*')
G[i][j][k] = '*';
else if (G[!i][j][k] == '#')
{
G[i][j][k] = G[!i][j][k] = '*';
}
}
else if (G[i][j][k] == 'S')
{
G[i][j][k] = '.';
scur = i;
sx = j;
sy = k;
}
else if (G[i][j][k] == 'P')
{
G[i][j][k] = '.';
ecur = i;
ex = j;
ey = k;
}
}
}
}
ans = 0;
bfs();
if (ans)
printf("YES\n");
else
printf("NO\n");
}
}

HDU - 2102 A计划 【BFS】的更多相关文章

  1. HDU 2102 A计划(BFS/DFS走迷宫)

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  2. hdu 2102 A计划-bfs

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  3. HDU - 2102 A计划 (BFS) [kuangbin带你飞]专题二

    思路:接BFS判断能否在限制时间内到达公主的位置,注意如果骑士进入传送机就会被立即传送到另一层,不会能再向四周移动了,例如第一层的位置(x, y, 1)是传送机,第二层(x, y, 2)也是传送机,这 ...

  4. HDU 2102 A计划 (BFS或DFS)

    题意:中文题. 析:是一个简单的搜索,BFS 和 DFS都可行, 主要是这个题有一个坑点,那就是如果有一层是#,另一个层是#或者*,都是过不去的,就可以直接跳过, 剩下的就是一个简单的搜索,只不过是两 ...

  5. HDU 2102 A计划(两层地图加时间限制加传送门的bfs)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others)    Me ...

  6. hdu 2102 A计划

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...

  7. hdu - 2102 A计划 (简单bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...

  8. hdu 2102 A计划(双层BFS)(具体解释)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...

  9. HDU 2102 A计划(BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...

随机推荐

  1. python 制作wordcloud词云

    pip install wordcloud 需要用到numpy  pillow matplotlib 安装完成以后 wordcloud_cli --text in.txt --imagefile ou ...

  2. NYOJ92 图像实用区域 【BFS】

    碰到了一个曾经从未见过的奇怪问题:先上截图: 执行号 用户 题目 结果 时间 内存 语言 提交时间 895360 userid=%E9%95%BF%E6%9C%A8" style=" ...

  3. day06_方法_20150806

    day06_方法_20150806 -------------------------回想:--------------------------------- 1.更佳适用情况       当---w ...

  4. bzoj1061【NOI2008】志愿者招募

    1061: [Noi2008]志愿者招募 Time Limit: 20 Sec  Memory Limit: 162 MB Submit: 2740  Solved: 1703 [Submit][id ...

  5. Web Service之Soap请求响应内容中文编码解密

    java模拟Soap请求测试Web Service接口,发现Web Service响应内容中的中文竟然是编码格式.比如: 中文:退保成功 Soap中文编码:退保成功   我仔细分析后发现,退编码实际上 ...

  6. Lua学习二----------Lua的基本语法

    © 版权声明:本文为博主原创文章,转载请注明出处 Lua基本语法: 1.--表示单行注释 2.--[[--]]表示多行注释 3.Lua区分大小写 4.Lua中变量默认是全局变量,除非用local显式声 ...

  7. Java NIO之Charset类字符编码对象

    介绍 java中使用Charset来表示编码对象 This class defines methods for creating decoders and encoders and for retri ...

  8. UML类图简明教程

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells Github:https://github.co ...

  9. oracle恢复已经删除的数据

    insert into tablerestore select * from tablerestore as of timestamp to_Date('2014-8-8 15:00:00','yyy ...

  10. LinkedList 基本示例及源码解析

    目录 一.JavaDoc 简介 二.LinkedList 继承接口和实现类介绍 三.LinkedList 基本方法介绍 四.LinkedList 基本方法使用 五.LinkedList 内部结构以及基 ...