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 ...
随机推荐
- AJPFX:外汇的爆仓和追加保证金
在外汇交易中,当可用保证金变成0时,账户即会爆仓.而为了防止爆仓,您可以在可用保证金不足时追加保证金以防止爆仓. 例如,您在AJPFX的账户是100倍的杠杆,一手欧美货币对合约为10万美金(1 LOT ...
- atomic write pipe
阅读 skynet 代码 socket_server 部分,发现对 socket 的写操作流程是这样的: 1. 各个服务(各线程)将数据写到 sendctrl_fd,这是一个 pipe 的 写端 2. ...
- 脚本中 if 判断细节
if [[ $1 == "fedora" ]];then echo "redhat" elif [[ $1 == "redhat" ]];t ...
- Shell - 简明Shell入门04 - 判断语句(If)
示例脚本及注释 #!/bin/bash var=$1 # 将脚本的第一个参数赋值给变量var if test $var # test - check file types and compare va ...
- HDFS概要
--HDFS-- Hadoop Distributed File System HDFS一个分布式,高容错,可线性扩展的文件系统 简介: Hadoop分布式文件系统(HDFS)是一种分布式文件系统,设 ...
- Docker 镜像安装 GitLab 中文社区版
docker run \ --detach \ --publish : \ --publish : \ --name gitlab \ --restart unless-stopped \ --vol ...
- (转)IBM AppScan 安全漏洞问题修复(.net)
原文:https://www.cnblogs.com/anngeiBKY/p/4952269.html 按问题类型分类的问题 使用 SQL 注入的认证旁路2 已解密的登录请求3 登录错误消息凭证枚举1 ...
- 【转载】CentOS中crontab定时计划任务的使用
转载自:http://blog.csdn.net/testcs_dn/article/details/48780971 概述 利用“任务计划”,可以将任何脚本.程序或文档安排在某个最方便的时间运行.通 ...
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(六):集成 Swagger API
spring-boot作为当前最为流行的Java web开发脚手架,越来越多的开发者选择用其来构建企业级的RESTFul API接口.这些接口不但会服务于传统的web端(b/s),也会服务于移动端.在 ...
- postgresql逻辑结构(一)
一.数据库逻辑结构介绍 数据库:应用连接到一个数据库时,一般不能访问其它数据库,除非使用dblink等其他手段. 表.索引:postgresql中标的术语为relation,其它数据库中成为table ...