这题太欢乐了......虽然wa了几次,但是想到骑士在两幅图的传送门中传来传去就觉得这骑士太坑了

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int n,m,cost,head,tail,ans;
char map[2][15][15];
int sum[2][15][15];
struct node {
int z,x,y;
} q[11111];
node st, end; int dirx[4] = {1,-1,0,0};
int diry[4] = {0,0,1,-1};
void init() {
memset(sum,-1,sizeof(sum));
ans = 0;
} bool go(int z,int x,int y) {
if(x < 0 || x >= n || y < 0 || y >= m) return false;
if(map[z][x][y] == '*') return false;
if(sum[z][x][y] != -1) return false; //
return true;
} int bfs() {
head = 0; tail = 0;
q[head++] = st;
sum[st.z][st.x][st.y] = 0;
while(head != tail) {
node t = q[tail++];
node tt;
if(end.z == t.z && end.x == t.x && end.y == t.y) {
if(cost >= sum[t.z][t.x][t.y]) {
return sum[t.z][t.x][t.y];
}
else return -1;
}
for(int i=0; i<4; i++) {
tt.z = t.z; tt.x = t.x + dirx[i]; tt.y = t.y + diry[i];
if(go(tt.z,tt.x,tt.y)) {
//cout << tt.z << ' ' << tt.x << ' ' << tt.y << endl;
if(map[tt.z][tt.x][tt.y] == '.' || map[tt.z][tt.x][tt.y] == 'P') {
sum[tt.z][tt.x][tt.y] = sum[t.z][t.x][t.y] + 1;
q[head++] = tt;
}
if(map[tt.z][tt.x][tt.y] == '#' && map[1 - tt.z][tt.x][tt.y] != '*' && map[1 - tt.z][tt.x][tt.y] != '#'){
sum[tt.z][tt.x][tt.y] = sum[t.z][t.x][t.y] + 1;
sum[1 - tt.z][tt.x][tt.y] = sum[tt.z][tt.x][tt.y];
tt.z = 1 - tt.z;
q[head++] = tt;
}
}
}
}
return -1;
} int main() {
int T;
cin >> T;
while(T --) {
init();
cin >> n >> m >> cost;
for(int z=0; z<2; z++)
for(int i=0; i<n; i++)
for(int j=0; j<m; j++) {
cin >> map[z][i][j];
if(map[z][i][j] == 'S') {
st.z = z;
st.x = i;
st.y = j;
}
if(map[z][i][j] == 'P') {
end.z = z;
end.x = i;
end.y = j;
}
}
if(bfs() == -1) printf("NO\n");
else printf("YES\n");
}
return 0;
}

HDU 2102 A计划(三维BFS)的更多相关文章

  1. HDU 2102 A计划 (三维的迷宫BFS)

    题目链接:pid=2102">传送门 题意: 三维的一个迷宫,起点在第一层的S(0,0,0)处,问是否能在规定的时间内走到第二层的P 处.'*'代表不能走,'.'代表能够走,'#'代表 ...

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

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

  3. HDU 2102 A计划(BFS)

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

  4. HDU - 2102 A计划 【BFS】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...

  5. HDU 2102 A计划 (BFS)

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

  6. hdu 2102 A计划(BFS,基础)

    题目 //要仔细写的BFS,着重对#穿越的处理哦: //花了几个小时终于把这道简单的BFS给弄好了,我果然还需要增加熟练度,需要再仔细一些: //代码有点乱,但我不想改了,,,,, #include& ...

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

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

  8. hdu 2102 A计划 具体题解 (BFS+优先队列)

    题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...

  9. hdu 2102 A计划

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

随机推荐

  1. PHP curl 采集内容之规则 1

    <?phpheader("Content-type:text/html; charset=utf-8");$pattern = '/xxx(.*)yyyy/isU'; //i ...

  2. [C#]『Task』任务并行库使用小计

    1.简单创建使用 using System; using System.Diagnostics; using System.Threading; using System.Threading.Task ...

  3. hbuider 中点击就显示出一个单选的列表 ,然后后台跨域向里面动态添加数据,注意里面的格式是json object

    jsp页面: <li class="mui-table-view-cell" onclick="showActionSheet()"> <di ...

  4. MFC 简单输出EXCEL - (OLE)

    三图胜千言: 就是酱紫: //打印领料表 void CKnifeDlgDlg::PrintCurUsedTabel(int order) { // TODO: Add your command han ...

  5. php不允许用户提交空表单(php空值判断)

    我们在设计提交空的评论时依然可以写入数据库,并在页面显示出来.这显然是不合理的,所以需要我们加入空值判断 可以修改代码,添加些判断: 复制代码代码如下:   if(empty($_POST['name ...

  6. 我用C#调用C编译的dll中有这样一个函数,函数大概的功能就是把数据保存到buf缓冲区中:

    我用C#调用C编译的dll中有这样一个函数,函数大概的功能就是把数据保存到buf缓冲区中: C/C++ code   ? 1 int retrieve(int scanno,void* buf); 在 ...

  7. wysiwyg editor

    http://www.bootcss.com/p/bootstrap-wysiwyg/

  8. python面向对象编程实例解析

    1. 类和函数 面向对象编程的例子: #!/usr/bin/env python # -*- coding: utf-8 -*- class Person(object): #在属性和变量的前面增加“ ...

  9. textarea宽度、高度自动适应处理方法

    textarea自动高度 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http: ...

  10. gdb调试高级用法

    Linux下进程崩溃时定位源代码位置 如何在调试内核时,同时可以调试应用程序的做法: (cskygdb) c Continuing. ^C Program received signal SIGINT ...