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 ...
随机推荐
- Servlet初步认知
1 背景概述 在近期的公司项目开发的过程中,笔者初步学习Servlet的开发.配置与使用,本文主要介绍了Servlet的相关概念以及优势说明并附上笔者开发简单样例.今天将笔者学习的心得总结出来与大家分 ...
- JQuery Mobile - html5+CSS 禁止IOS长按复制粘贴实现
因为在移动端APP需要实现长按执行别的事件,但是在IOS系统有默认的长按选择复制粘贴,禁止此功能在网上找了很多资料,最终整理出目前最好的解决方法.实际测试,也并不是很理想,但是可能没有更好办法了! / ...
- 防止sql注入的小函数 以及一些小验证
function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialch ...
- Java并发编程总结2——慎用CAS
一.CAS和synchronized适用场景 1.对于资源竞争较少的情况,使用synchronized同步锁进行线程阻塞和唤醒切换以及用户态内核态间的切换操作额外浪费消耗cpu资源:而CAS基于硬件实 ...
- pika配置文件说明
# Pika 端口 port : 9221 # pika进程数量,不建议超过核心数量,pika是多线程的 thread-num : 1 # Sync 线程数量 sync-thread-num : 6 ...
- 移动端font-size适配方案
概述 这是我研究移动端页面时的思考,记录下来供以后开发时参考,相信对其他人也有用.由于我写移动端页面写的还比较少,一些问题都还没遇到,所以我的这篇博文不免有些错误的地方,还请大佬多多指正. 这篇文章是 ...
- harbor镜像仓库-01-搭建部署
harbor镜像仓库-01-搭建部署 dockerregistryharbor安装部署docker-compose harbor的https配置参考另一章节harbor镜像仓库-02-https访问配 ...
- cytoscape.js在vue项目中的安装及案例
1. 安装: npm i cytoscape --save 2. 引入:main.js import cytoscape from 'cytoscape'; Vue.prototype.$cytosc ...
- C++(初学讲解):判断倍数
问题描述输入一个整数,如果是5的倍数,那么输出倍数的值,否则输出NO. 输入描述一个整数. 输出描述输出倍数的值或者NO. 输入示例15 输出示例3 #include <iostream> ...
- vs2017配置pthread.h的方法
一.背景(以下为走不通的配置方法!) 笔者最开始配置pthread.h,采用的是vs自动安装的方法,如图所示. 点击完“管理NuGet程序包”之后,弹出一个页面,如下,在“浏览”中输入pthread. ...