A计划 hdu2102(bfs一般题)
A计划
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7543 Accepted Submission(s): 1795
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 15
char a[][maxn][maxn];
int n,m,T,count;
int vis[][maxn][maxn];
int dir[][]={{,},{,},{-,},{,-}}; int chear(int x,int y)
{
if(x<||x>=n||y<||y>=m)
return ;
else
return ;
} struct node
{
int x;
int y;
int layer;//层
int step;
}; queue<node>Q; void bfs()
{ node now,next;
now.x=;
now.y=;
now.layer=;
now.step=;
vis[now.layer][now.x][now.y]=;
Q.push(now);
while(!Q.empty())
{
now=Q.front();
Q.pop();
if(now.step>T)
break ;
if(a[now.layer][now.x][now.y]=='P'&&now.step<=T)
{
printf("YES\n");
return ;
}
for(int i=;i<;i++)
{
next.x=now.x+dir[i][];
next.y=now.y+dir[i][];
next.layer=now.layer;
if(chear(next.x,next.y)||a[next.layer][next.x][next.y]=='*'||vis[next.layer][next.x][next.y])
continue;
next.step=now.step+;
vis[next.layer][next.x][next.y]=;
if(a[next.layer][next.x][next.y]=='#'&&a[!next.layer][next.x][next.y]!='*'&&a[!next.layer][next.x][next.y]!='#')
{
next.layer=-next.layer;
next.step=now.step+;//传输过去记得也要记录时间,不然下一层时间不对,WA了好几次,,,,
vis[next.layer][next.x][next.y]=;
Q.push(next);
}
else if(a[next.layer][next.x][next.y]=='.'||a[next.layer][next.x][next.y]=='P')
Q.push(next);
}
}
printf("NO\n");
}
int main()
{
int C,i,j;
scanf("%d",&C);
while(C--)
{
scanf("%d%d%d",&n,&m,&T);
// getchar();
for(i=;i<n;i++)
cin>>a[][i];
// printf("%c\n",a[0][0][0]);
// for(i=0;i<n;i++)
// cout<<a[0][i]<<endl;
getchar();
for(i=;i<n;i++)
cin>>a[][i];
// for(i=0;i<n;i++)
// cout<<a[1][i]<<endl;
memset(vis,,sizeof(vis));
while(!Q.empty())//Q必须得被清空 勿忘!!!
Q.pop();
bfs();
}
}
/*
5
5 5 14
S*#*.
.#...
.....
****.
...#. ..*.P
#.*..
***..
...*.
*.#..
5 5 14
S*#*.
.#...
.....
****.
...#. ..*.P
#.*..
***..
...**
*.#..
5 5 14
S*#*.
.#...
.....
****.
...#. ..*.P
#.*.*
****.
...*.
*.#..
5 5 14
S*#*.
.#...
.....
****.
...#. ..*..
#.*..
***..
...*.
*.#..
5 5 14
S*#*.
.#...
....#
***..
...#. ..*.P
#.*.*
***.#
...*.
*.#.. */
貌似没什么好说的了,,,一起努力,一起加油! 就这样。
A计划 hdu2102(bfs一般题)的更多相关文章
- A计划 hdu2102(BFS)
A计划 hdu2102 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国 ...
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- BFS简单题套路_Codevs 1215 迷宫
BFS 简单题套路 1. 遇到迷宫之类的简单题,有什么行走方向的,先写下面的 声明 ; struct Status { int r, c; Status(, ) : r(r), c(c) {} // ...
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- [NOIP补坑计划]NOIP2017 题解&做题心得
终于做完了…… 场上预计得分:?(省一分数线:295) 由于看过部分题解所以没有预计得分qwq 题解: D1T1 小凯的疑惑 题面 震惊!一道小学奥数题竟难倒无数高中考生! 欢迎大家以各种姿势*和谐* ...
- HDU_2102 A计划 【BFS】
一.题目 HDU2102 二.题意分析 该题其实就是三位空间内的BFS,但比较简单的是,它设置了传送门,可以直接传送上去,需要注意的是 1.到了传送门的时候要重新考虑传送的点的三种情况. (1)若又是 ...
- 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)
-->A计划 Descriptions: 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的 ...
- hdu1240 bfs 水题
原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...
随机推荐
- 1.翻译:EF基础系列--什么是Entity Framework?
大家好,好久不见,EF系列之前落下了,还是打算重新整理一下. 先说说目前的打算:先简单了解一下EF基础系列-->然后就是EF 6 Code-First系列-->接着就是EF 6 DB-Fi ...
- Android开发教程 - 使用Data Binding(一) 介绍
本系列目录 使用Data Binding(一)介绍 使用Data Binding(二)集成与配置 使用Data Binding(三)在Activity中的使用 使用Data Binding(四)在Fr ...
- JQuery Mobile - 处理图片加载失败!
重点来了:一定要记住error事件不冒泡(如果要用js的方法替换默认出错图片,记得把img的alt属性去掉). 相关的知识点:jquery的ready方法.$("img").err ...
- Quartz是一个任务调度
这段时间做一个案子,用到每天定时处理事件,之前的解决思路是通过一个定时器轮询时间段,这样不能精准的在某个时间戳上执行动作.由于没有用过Quartz是一个任务调度,一直使用这个办法,今天通过同事提点,从 ...
- Python 生成器, 迭代器, 可迭代对象的区别
1.可迭代对象 在python中, 一切皆对象, 但凡是可以用for循环进行遍历取值的对象都可以称之为可迭代对象, 可迭代对象在程序的一个执行周期中,可以无限轮次的进行循环遍历 2.迭代器 a.一个可 ...
- 在window主机上访问virtualbox虚拟机上centos7的tomcat服务
在virtualbox上装完centos7后,随后装了tomcat服务器,然后在主机上发现用google浏览器访问tomcat不了 于是用ping检测下,发现ping不通,经过多方查找,才配置好,于是 ...
- 【xsy1130】tree 树形dp+期望dp
题目写得不清不楚的... 题目大意:给你一棵$n$个节点的树,你会随机选择其中一个点作为根,随后随机每个点深度遍历其孩子的顺序. 下面给你一个点集$S$,问你遍历完$S$中所有点的期望时间,点集S中的 ...
- tensorflow学习总结之reduce_sum函数
tensorflow里面集成了许多基于统计的数学函数,类似于reduce_sum,reduce_mean,reduce_min,reduce_max,等,根据字面意思分别是求和,求平均,求最大,求最小 ...
- Shell常见的快捷键
Ctrl + a - Jump to the start of the lineCtrl + b - Move back a charCtrl + c - Terminate the command ...
- Log4j最佳实践
本文是结合项目中使用Log4j总结的最佳实践,非转载.网上可以找到的是这一篇<Log4j最佳实践>.本来Log4j使用是非常简单的,无需多介绍其用法,这只是在小型项目中:但在大型的项目中使 ...