这题太欢乐了......虽然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. javascript 节点属性详解

    javascript 节点属性详解 根据 DOM,html 文档中的每个成分都是一个节点 DOM 是这样规定的:整个文档是一个文档节点每个 html 标签是一个元素节点包含在于 html 元素中的文本 ...

  2. php设计模式笔记:单例模式

    php设计模式笔记:单例模式 意图: 保证一个类仅有一个实例,并且提供一个全局访问点 单例模式有三个特点: 1.一个类只有一个实例2.它必须自行创建这个实例3.必须自行向整个系统提供这个实例 主要实现 ...

  3. xml转array

    1.字串 $xml = simplexml_load_string($data);$array = json_decode(json_encode($xml),TRUE); 2.文件$xml = si ...

  4. 安装Oracle 11gR2,报错:[INS-06101] IP address of localhost could not be determined

    安装Oracle 11gR2,报错:[INS-06101] IP address of localhost could not be determined 出现这种错误是因为主机名和/etc/host ...

  5. asp.net与MVC4的路由原理和过程【学习笔记】

    当IIS收到一个http请求,把请求信息发给对应的HttpModel(实际是实现类UrlRoutingModule),在HttpModel中会注册HttpApplication 类中的PostReso ...

  6. jquery经验1

    1.Javascript刷新页面的几种方法: location.reload()// 真刷新 location=location location.assign(location) document. ...

  7. python url解析

    >>> url="http://localhost/test.py?a=hello&b=world " >>> result=urlpa ...

  8. redis基本命令的演示:

    import redis r = redis.Redis(host='127.0.0.1', port=6379,db = 0) #查看匹配redis的数据 r.keys() #查看redis的大小 ...

  9. keychain 多应用共享数据

    地址:http://blog.csdn.net/jerryvon/article/details/16843065 补充: 若plist跟项目不在同一级目录下,可通过XXX/xxx.plist的方式设 ...

  10. ZOJ 2562 More Divisors

    又是个水题,刚刚开始没有用搜索,因为对于反素数有: n=2^t1*3^t2^5^t3*7^t4..... 这里有 t1>=t2>=t3>=t4. 而且相同的因数的情况下,素数越不同越 ...