一、题目

HDU2102

二、题意分析

该题其实就是三位空间内的BFS,但比较简单的是,它设置了传送门,可以直接传送上去,需要注意的是

1.到了传送门的时候要重新考虑传送的点的三种情况。

  (1)若又是传送门,这两个点都可以不再考虑了。

  (2)若是墙,如题意,直接pass掉。

  (3)若是P,找到了。

2.在T之前找到公主后也是可以的合理解释是不是骑士和公主可以在那里聊到T时刻?

三、AC代码

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <fstream>
#include <queue> using namespace std; int N, M, T;
const int dx[] = {, , , -};
const int dy[] = {, -, , };
char Map[][][];
bool visit[][][];
struct Node
{
int level, x, y;
}S, P;
// Node Q[1000000];
// int Rea, Cnt;
bool judge(Node t)
{
if(t.level < || t.level >= || t.x < || t.x >= N || t.y < || t.y >= M
|| Map[t.level][t.x][t.y] == '*' || visit[t.level][t.x][t.y] == )
return false;
return true;
} bool BFS()
{
memset(visit, , sizeof(visit));
queue<Node> Q;
Q.push(S); // Cnt = Rea = 0;
// Q[Cnt++] = S;
visit[S.level][S.x][S.y] = ; for(int t = ; t <= T; t++)
{
int size = (int)Q.size();
//int size = Cnt - Rea;
while(size--)
{
Node cur = Q.front();
Q.pop();
//Node cur = Q[Rea++]; for(int i = ; i < ; i++)
{
Node next = cur;
next.x += dx[i];
next.y += dy[i];
if(judge(next))
{
if(Map[next.level][next.x][next.y] == '#')
{
visit[next.level][next.x][next.y] = ;
next.level++;
next.level%=;
if(!judge(next))
continue;
}
if(Map[next.level][next.x][next.y] == '#')
{
visit[next.level][next.x][next.y] = ;
continue;
}
else if(Map[next.level][next.x][next.y] == 'P')
{
return true;
}
else
{
visit[next.level][next.x][next.y] = ;
Q.push(next);
}
//Q[Cnt++] = next;
}
}
}
}
return false; } int main()
{
//freopen("input.txt", "r", stdin);
int C;
scanf("%d", &C);
while(C--)
{
scanf("%d %d %d", &N, &M, &T);
for(int i = ; i < ; i++)
{
for(int j = ; j < N; j++)
{
scanf("%s", Map[i][j]);
for(int k = ; k < M; k++)
{
if(Map[i][j][k] == 'S')
{
S.level = i;
S.x = j;
S.y = k;
}
else if(Map[i][j][k] == 'P')
{
P.level = i;
P.x = j;
P.y = k;
}
}
}
getchar();
}
if(BFS())
printf("YES\n");
else
printf("NO\n");
}
return ;
}

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. A计划(BFS)

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

  3. HDU2102 A计划 —— BFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others)    Me ...

  4. hdu 2102 A计划-bfs

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

  5. HDOJ 2102 A计划(bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路分析: <1>搜索方法分析:由于需要寻找最短的找到公主的路径,所以采用bfs搜索 ...

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

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

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

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

  8. A计划(bfs)

    A计划 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  9. A计划(双层bfs)

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

随机推荐

  1. ARCGIS空间叠加分析(转)

    ARCGIS空间叠加分析 https://blog.csdn.net/gswwldp/article/details/66974465 (2)双击④处的Identity,打开Identity操作对话框 ...

  2. 关于使用sessionStorage报SecurityError错误的问题

    localStorage 永久保存 不同页面和标签页可以共享 关闭浏览器不会清除 sessionStorage 会话保存 不同页面和标签页不能共享 关闭浏览器会清除 遇到的问题:在firefox中报S ...

  3. 阿里云ECS购买优惠码

    今天收到了阿里云给我发的邮件,大意是阿里云推荐码限量开放,可享九折优惠! 于是就点击进去申请了一下 申请的优惠码是:C7IYIS有效期至2015-11-30 23:59:59 首次购买包年包月云服务器 ...

  4. 【项目运行异常】BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

    java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking ...

  5. ubuntu 14.04编译安装xen4.4总结

    1. 安装环境 操作系统:ubuntu14.04 xen版本:xen4.4 2. 依赖包的安装 在安装xen之前先进行依赖包的安装,在不停得尝试之后,总结出以下需要安装的依赖包. sudo apt-g ...

  6. OkHttp3的简单使用(二)

    OkHttp3的简单封装 public class OkHttpUtil { public static final String TAG="OkHttpUtil"; privat ...

  7. tomcat的内存配置,关于-Xms -Xmx -XX:PermSize -XX:MaxPermSize的理解和区别

    JVM按照其存储数据的内容将所需内存分配为堆区与非堆区两个部分:所谓堆区即为通过new的方式创建的对象(类实例)所占用的内存空间:非堆区即为代码.常量.外部访问(如文件访问流所占资源)等.然而虽然ja ...

  8. logback-记录日志

      一:根节点<configuration>包含的属性: scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true. scanPeriod: 设置监测配 ...

  9. C#截取验证码图片

    使用Graphics类中的DrawImage方法,这个方法有30种重载方式,这里只介绍一种,也是我认为最直观的一种,代码如下: using System.Drawing; namespace kq.U ...

  10. Linux 内核list_head 学习

    Linux 内核list_head 学习(一) http://www.cnblogs.com/zhuyp1015/archive/2012/06/02/2532240.html 在Linux内核中,提 ...