题目链接

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. 最长递增子序列问题—LIS

    问题:给定一组数 a0,a0,....,an-1. 求该序列的最长递增(递减)序列的长度. 最长递增子序列长度的求法有O(n^2)和O(nlogn)两种算法. 1.复杂度为O(n^2)的算法. 设L[ ...

  2. jquery 判断元素显示或隐藏

    $().is(":hidden"); $().is(":visible");

  3. SQL CASE WHEN ... THEN ... ELSE.. END 实例

    用一个SQL语句完成不同条件的分组(SELECT部分): select QuoteOrderId,SUM(case when(ApprovalStatus=1)then Amount else 0 e ...

  4. Android · PendingIntent学习

    Intent 是及时启动,intent 随所在的activity 消失而消失 PendingIntent用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转.   ...

  5. C语言数据类型的转换

    C语言的类型转换,一个是强制类型进行转换,而在这里要介绍的是自动的数据类型的转换,自动的数据类型转换很多时候是发生在多种数据类型混合使用的时候就会进行类型的转换,这样就会带来不能控制的结果,所以必须进 ...

  6. Java使用笔记之stream和sorted使用

    //对象类型stream排序List<User> users = new ArrayList<User>(){ { add(new User("a", &q ...

  7. Struts2学习一----------Struts2的工作原理及HelloWorld简单实现

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2工作原理 一个请求在Struts2框架中的处理步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求 2.这个请求 ...

  8. jdk并发工具包之锁

    1.cynchronized扩展:可重锁入ReentrantLock ReentrantLock是通过cas算法实现的 RenntrantLock lock=new ReentrantLock(); ...

  9. Python,Pycharm,Anaconda等的关系与安装过程~为初学者跳过各种坑

    1.致欢迎词 我将详讲讲述在学Python初期的各种手忙脚乱的问题的解决,通过这些步骤的操作,让你的注意力集中在Python的语法上以及后面利用Python所解决的项目问题上.而我自己作为小白,很不幸 ...

  10. 有一个投篮游戏。球场有p个篮筐,编号为0,1...,p-1。每个篮筐下有个袋子,每个袋子最多装一个篮球。有n个篮球,每个球编号xi 。规则是将数字为xi 的篮球投到xi 除p的余数为编号的袋里。若袋里已有篮球则球弹出游戏结束输出i,否则重复至所有球都投完。输出-1。问游戏最终的输出是什么?

    // ConsoleApplication5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<vector> ...