HDU 2102 A计划(三维BFS)
这题太欢乐了......虽然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)的更多相关文章
- HDU 2102 A计划 (三维的迷宫BFS)
题目链接:pid=2102">传送门 题意: 三维的一个迷宫,起点在第一层的S(0,0,0)处,问是否能在规定的时间内走到第二层的P 处.'*'代表不能走,'.'代表能够走,'#'代表 ...
- hdu - 2102 A计划 (简单bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...
- HDU 2102 A计划(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...
- HDU - 2102 A计划 【BFS】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...
- HDU 2102 A计划 (BFS)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 2102 A计划(BFS,基础)
题目 //要仔细写的BFS,着重对#穿越的处理哦: //花了几个小时终于把这道简单的BFS给弄好了,我果然还需要增加熟练度,需要再仔细一些: //代码有点乱,但我不想改了,,,,, #include& ...
- HDU 2102 A计划(两层地图加时间限制加传送门的bfs)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others) Me ...
- hdu 2102 A计划 具体题解 (BFS+优先队列)
题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...
- hdu 2102 A计划
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
随机推荐
- c#代码自动修改解决方案下任意文件
命名空间 using EnvDTE;using EnvDTE80; private DTE2 _applicationObject; public void AutoAddControl(插件 v_f ...
- H5小内容(二)
音视频处理 视频处理 基本内容 使用Flash技术处理HTML页面中的视频内容 包含音频.动画.网页游戏等 特点 浏览器原生不支持(IE浏览器要求安装A ...
- jQuery移除指定元素后的所有元素
jQuery 遍历的nextAll() 方法可以搜索 DOM 树中的元素跟随的同胞元素,也就是一个元素后面的所有同级元素,删除可以使用方法remove(),所以连起来为 $(selector).nex ...
- 用javascript操作xml(二)JavaScript 将XML转换成字符串(xml to string)
function xmlToString(xmlData) { var xmlString; //IE if (window.ActiveXObject){ xmlString = xmlData.x ...
- C# MySql 操作类
/* MySql 类 */ using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- 由css属性:vertial-align想到的。。
我的笔记本:型号 acer4750G-2412g50mnkk 分辨率:1333*768,点距:0.25933mm; 12px下的font-size: 默认line-height减去font-size: ...
- STM32固件库
一.STM32固件库开发和传统寄存器开发方式的区别 二.CMSIS标准 CMSIS标准--Cortex Microcontroller Software Interface Standard,是ARM ...
- iOS - 沙盒机制
iOS应用程序只能在为该程序创建的文件系统中读取文件,不可以去其他地方访问,此区域被称为沙盒.所有的非代码文件都要保存在此,例如图像,图标,声音,属性列表(plist文件),文本文件等.沙盒机制作为一 ...
- Dom学习笔记-(一)
一.概述 DOM(文档对象模型)是针对HTML和XML文档的一个API,其脱胎于DHTML. DOM可以将任意HTML和XML文档描绘成一个由多层节点构成的结构. 每一个文档包含一个根节点-文档节点, ...
- POJ2103 Jackpot
Description The Great Dodgers company has recently developed a brand-new playing machine. You put a ...