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 ...
随机推荐
- 【BZOJ2001】 [Hnoi2010]City 城市建设
BZOJ2001 [Hnoi2010]City 城市建设 Solution 我们考虑一下这个东西怎么求解? 思考无果...... 咦? 好像可以离线cdq,每一次判断一下如果这条边如果不选就直接删除, ...
- 【文文殿下】[CEOI2004]锯木厂选址 题解
题解 我们枚举建厂的位置,发现有个\(n^2\)的DP.随手搞个斜率优化到\(O(n)\). #include<bits/stdc++.h> using namespace std; ty ...
- PHP 调试工具Xdebug安装配置
## PHP 调试工具Xdebug安装配置 一.Xdebug 介绍 Xdebug是一个开源的PHP程序调试工具,可以使用它来调试.跟踪及分析程序运行状态.当然,Xdebug需要结合PHP的编辑工具来打 ...
- 【小程序开放激励视频】--wepy小程序添加激励视频
小程序开放激励视频是对小程序开发者一个福音,小程序开发者可以完成一些变现,以增加收入! 本文章针对已经有开发经验或者正在进行小程序开发的同学~ 官方文档:激励视频广告 定义页面变量,用于创建视频实例 ...
- Others - On Duty
On Duty This is xxx and will be duty engineer in the next week. Thanks. Here is a kindly reminder. T ...
- Java按时间梯度实现异步回调接口
1. 背景 在业务处理完之后,需要调用其他系统的接口,将相应的处理结果通知给对方,若是同步请求,假如调用的系统出现异常或是宕机等事件,会导致自身业务受到影响,事务会一直阻塞,数据库连接不够用等异常现象 ...
- 大数据与Hadoop
figure:first-child { margin-top: -20px; } #write ol, #write ul { position: relative; } img { max-wid ...
- odoo开发笔记--odoo可用小图标
odoo系统的小图标都采用了 fontawesome字体图标 官网: http://fontawesome.dashgame.com/ Github:http://fortawesome.github ...
- 关于Python2和Python3之间的文本模型改变
原文地址:http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html#what-act ...
- MyBatis中如何一次执行多条语句(使用mysql数据库)
解决办法不外乎有三个:1.多条sql分批执行:2.存储过程或函数调用:3.sql批量执行. MyBatis中如何一次执行多条语句(使用mysql数据库): 1.修改数据库连接参数加上allowMult ...