hdu 2102 A计划(bfs)
来源:互联网 发布:彩票代买软件 编辑:程序博客网 时间:2024/04/30 07:28
现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。
15 5 14S*#*..#........****....#...*.P#.*..***.....*.*.#..
YES
基础bfs
#include <iostream>
#include <stdio.h>
#include <queue>
#include <string.h>
using namespace std;
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
char map[2][15][15];
bool vis[2][15][15];
int n,m,t;
struct node
{
int x,y,z;
int step;
node(int x=0,int y=0,int z=0,int step=0)
{
this->x=x;
this->y=y;
this->z=z;
this->step=step;
}
};
bool check(int x,int y,int z)
{
if(x<0|| x>=n || y<0 || y>=m ||map[z][x][y]=='*' )
{
return false;
}
return true;
}
bool bfs()
{
queue<node>q;
q.push(node(0,0,0,t));
vis[0][0][0]=1;
node temp,t;
while (!q.empty())
{
t=q.front();
q.pop();
for (int i=0; i<4; i++)
{
temp=t;
temp.x+=dir[i][0];
temp.y+=dir[i][1];
temp.step--;
if(temp.step<0)
return false;
if(check(temp.x, temp.y,temp.z) && !vis[temp.z][temp.x][temp.y])
{
if(map[temp.z][temp.x][temp.y]=='#')
temp.z^=1;
if(map[temp.z][temp.x][temp.y]=='P')
return true;
else if(map[temp.z][temp.x][temp.y]!='*')
{
vis[temp.z][temp.x][temp.y]=1;
q.push(temp);
}
}
}
}
return false;
}
int main()
{
int c;
scanf("%d",&c);
while (c--)
{
scanf("%d%d%d",&n,&m,&t);
memset(vis,false, sizeof(vis));
getchar();
for (int i=0; i<2; i++)
{
for (int j=0; j<n; j++)
{
scanf("%s",map[i][j]);
}
getchar();
}
for (int i=0; i<2; i++)
{
for (int j=0; j<n; j++)
{
for (int k=0; k<m; k++)
{
if(map[i][j][k]=='#' &&map[1^i][j][k]=='*')
map[i][j][k]='*';
if(map[i][j][k]=='#' &&map[1^i][j][k]=='#')
map[i][j][k]=map[1^i][j][k]='*';
}
}
}
if(bfs())
puts("YES");
else
puts("NO");
}
return 0;
}
- HDU 2102 A计划(BFS)
- hdu 2102 A计划 (bfs+队列)
- hdu 2102 A计划(bfs)
- HDU 2102 A计划 (BFS + 预处理)
- HDU 2102 A计划 (BFS)
- 【HDU 2102】A计划(BFS)
- HDU-2102-A计划(BFS)
- HDU 2102 A计划(bfs + 判断)
- HDU 2102 A计划(三维BFS)
- HDU 2102 A 计划(bfs)
- HDU 2102 A计划 BFS
- hdu 2102 A计划 BFS
- HDU 2102 A计划(BFS)
- hdu 2102 A计划 (bfs)
- Hdu 2102 A计划 [Bfs]
- HDU 2102 A计划 BFS
- HDU 2102--A计划【BFS】
- HDU 2102 A计划 BFS
- JNI调用 java.lang.UnsatisfiedLinkError 异常
- oracle中 connect by prior 递归算法
- git clone 远程分支
- win下php扩展下载。。
- 用gson将JSON转换为List
- hdu 2102 A计划(bfs)
- LTE网络主要接口信息
- 二叉排序树的基本操作
- plsql连接oracle
- Logistic回归总结
- Laravel国内镜像
- 关系型数据库的内外连接
- ConfigParser
- 高通810高热该谁背锅?那就是Apple!!