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 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
随机推荐
- Linux之C编译器gcc和makefile使用简介
使用gcc编译程序是,其过程主要分为四个阶段:预处理,编译,汇编,连接 程序清单: #include<stdio.h> #include<stdlib.h> int main( ...
- css reset浅谈
我们都知道,web开发中浏览器兼容性是困扰很多开发者的一个问题.所谓兼容性问题,即不同浏览器对同一段代码有不同的解析效果.而我们的需求往往是无论用户使用何种浏览器查看我们的网站,都应该获得相同或相近的 ...
- ECMAScript 5正式发布
这周ECMAScript 5也即众所周知的JavaScript正式发布了(pdf),在给基本库带来更新的同时,还引入了更加严格的运行时模型,来帮助定位并移除通常的代码错误. 而早期对于ECMAScri ...
- WPF窗体禁用最大化按钮
禁用WPF窗体的最大化按钮可以使用Windows API改变按钮状态的方法实现.使用GetWindowLong可以得到当前按钮的状态.使用SetWindowLong可以设置按钮的状态.使用SetWin ...
- SQLSERVER与C#中数据类型的对应关系
SQLSERVER与C#中数据类型的对应关系 ///<summary> ///数据库中与C#中的数据类型对照 ///</summary> ///<paramname=&q ...
- BestCoder Round #67 (div.2) N*M bulbs
问题描述 N*M个灯泡排成一片,也就是排成一个N*M的矩形,有些开着,有些关着,为了节约用电,你要关上所有灯,但是你又很懒. 刚好有个熊孩纸路过,他刚好要从左上角的灯泡走去右下角的灯泡,然后离开. 但 ...
- css小心德
内部块最好用百分比,微调时方便
- tpl demo
using System; using System.Collections.Concurrent; using System.Threading; using System.Threading.Ta ...
- Codeforces Round #321 div2
好像前几场的题解忘记写了, Orz 状态太差, 平均出两题 都不好意思写了 , 连掉4场, 都要哭晕了. 很水的一场, 写完A B C就去睡了 D题其实不难, E题研究Ing(已用一种奇怪的姿势 ...
- django中form表单的提交:
一,关于表单: 表单在百度百科的解释: 表单在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用CGI程序的URL以及数据提交到服务器的方法. 表单域 ...