题目链接

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. 2017.2.13 开涛shiro教程-第十二章-与Spring集成(二)shiro权限注解

    原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(二)shiro权限注解 shiro注 ...

  2. centos 7 安装五笔输入法

    centos 7 安装五笔输入法 [a@endv ~]$ yum search wubi 已加载插件:fastestmirror, langpacks Loading mirror speeds fr ...

  3. browsersync按照官网,然后本地配置后,动态监听时不起作用

    官方API也未曾标注,要添加文件指向 --files 所以解决方案就是: browser-sync start --proxy "tp5.cn" --files "css ...

  4. spring(16)------spring的数据源配置

    在spring中,通过XML的形式实现数据源的注入有三种形式. 一.使用spring自带的DriverManagerDataSource 使用DriverManagerDataSource配置数据源与 ...

  5. React学习之事件绑定

    React事件绑定有主要有三种方式 第一种官方推荐方式: class LoginControl extends React.Component {   constructor(props) {     ...

  6. FileUpload控件预览图片

    HTML代码: <tr> <td class="auto-style1">上传图片:</td> <td> <asp:FileU ...

  7. LeetCode Hash Table 3. Longest Substring Without Repeating Characters

    HashMap的应用可以提高查找的速度,键key,值value的使用拜托了传统数组的遍历查找方式,对于判断一个字符或者字符串是否已经存在的问题可以非常好的解决.而本题需要解决的问题就是判断新遍历到的字 ...

  8. BZOJ 1293 SCOI2009 生日礼物 堆

    题目大意:给定一个数轴上n个点,每一个点有一种颜色,一共k种颜色.求一个最短的区间,包括全部k种颜色 卡了一段时间0.0 一開始想二分答案啥的 后来发现数据范围太大写不了0.0 后来去找题解才发现尼玛 ...

  9. mysql索引类型normal,unique,full text

    normal:表示普通索引 unique:表示唯一的,不允许重复的索引,如果该字段信息保证不会重复例如身份证号用作索引时,可设置为unique full textl: 表示 全文搜索的索引. FULL ...

  10. 原创 | 我被面试官给虐懵了,竟然是因为我不懂Spring中的@Configuration

    GitHub 3.7k Star 的Java工程师成神之路 ,不来了解一下吗? GitHub 3.7k Star 的Java工程师成神之路 ,真的不来了解一下吗? GitHub 3.7k Star 的 ...