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 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
随机推荐
- 【转】Ext JS xtype
原文:Ext 中xtype一览 基本组件: xtype Class 描述 button Ext.Button 按钮 splitbutton Ext.SplitButton 带下拉菜单的按钮 cyc ...
- php练习5——简单的学生管理系统(隐藏控件的使用)
要求: 程序:gradeManage.html和gradeManage.php 结果 注意: 1.使用隐藏控件时,得在不同表单下,不能在同一个表单下: 2. ...
- Mysql存储过程知识,案例--mysql存储过程基本函数
Mysql存储过程知识,案例: create procedure delete_setting(in p_settingid integer) begin delete from setting wh ...
- Improved Semantic Representations From Tree-Structured Long Short-Term Memory Networks(1)
今天和陈驰,汪鑫讨论了一下,借此记录一下想法. 关于这篇论文,要弄清的地方有: 1.LSTMtree到底是从上往下还是从下往上学的,再确认一下 2.关于每个节点的标注问题 3.label的值到底该怎么 ...
- MDK建立STM32F103*开发模板
一.整体流程 1.获取ST库--STM32F10x_StdPeriph_Lib_V3.5.0 2.新建文件夹并加载文件 3.新建工程 4.给工程添加组 5.设置"Target Option& ...
- cocos2d-x笔记5: 通过jni实现C++调用Java
Cocos2d-x的跨平台性很强大,但是偶尔也需要平台的原生API结合. C++在Win32平台下简单的很,C++可以直接用MFC或者调用Win32API. Ios在XCode下直接就能C++和OC混 ...
- JVM 学习笔记
1. JAVA类分为三类: 1.1 系统类 (用系统类加载器加载bootstrap ClassLoader) 1.2 扩展类 (用扩展类加载器加载Ext ClassLoader) 1. ...
- [转贴] C/C++中动态链接库的创建和调用
DLL 有助于共享数据和资源.多个应用程序可同时访问内存中单个DLL 副本的内容.DLL 是一个包含可由多个程序同时使用的代码和数据的库.下面为你介绍C/C++中动态链接库的创建和调用. 动态连接库的 ...
- leetcode面试准备:Minimum Size Subarray Sum
leetcode面试准备:Minimum Size Subarray Sum 1 题目 Given an array of n positive integers and a positive int ...
- Android 窗口管理
一.概述 在Android系统中,从设计的角度来看,窗口管理系统是基于C/S模式的.整个窗口系统分为服务端和客户端两大部分,客户端负责请求创建窗口和使用窗口,服务端完成窗口的维护,窗口显示等. 在Cl ...