HDU 2102 A计划 (三维的迷宫BFS)
题目链接: pid=2102">传送门
题意:
三维的一个迷宫,起点在第一层的S(0,0,0)处,问是否能在规定的时间内走到第二层的P
处。'*'代表不能走,'.'代表能够走,'#'代表传送门,这里有一个trick,走到传送门的时
候必需要传送。之前没有注意到WA了非常多遍。
并且在初始的时候能够对地图进行一下处理,('*','#'),('#','*'),('#','#')这种肯定
是不能够走的,所以能够把他们都变成'*'
代码例如以下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std; const int maxn = 50; char mp[2][maxn][maxn]; int vis[2][maxn][maxn]; int dx[4]= {1,-1,0,0};
int dy[4]= {0,0,-1,1}; int n,m,limit; struct nod {
int x,y,z;
int step;
nod() {}
nod(int _x,int _y,int _z):x(_x),y(_y),z(_z) {}
}; bool check(nod tmp){
if(vis[tmp.z][tmp.x][tmp.y]) return false;
if(tmp.x>=0&&tmp.x<n&&tmp.y>=0&&tmp.y<m&&mp[tmp.z][tmp.x][tmp.y]!='*') return true;
return false;
} bool bfs() {
nod st=nod(0,0,0);
vis[0][0][0]=1;
st.step=0;
queue<nod> Q;
Q.push(st);
while(!Q.empty()) {
nod tmp = Q.front();
//cout<<tmp.z<<" "<<tmp.x<<" "<<tmp.y<<" "<<tmp.step<<endl;
Q.pop();
if(mp[tmp.z][tmp.x][tmp.y]=='P'&&tmp.step<=limit) {
return true;
} else if(mp[tmp.z][tmp.x][tmp.y]=='P') {
return false;
}
for(int i=0; i<4&&mp[tmp.z][tmp.x][tmp.y]!='#'; i++) {
nod top;
top.x=tmp.x+dx[i],top.y=tmp.y+dy[i],top.z=tmp.z,top.step=tmp.step+1;
if(check(top)){
Q.push(top);
vis[top.z][top.x][top.y]=1;
}
}
if(mp[tmp.z][tmp.x][tmp.y]=='#'){
tmp.z^=1;
Q.push(tmp);
vis[tmp.z][tmp.x][tmp.y]=1;
}
}
return false;
} int main() {
int t;
scanf("%d",&t);
while(t--) {
scanf("%d%d%d",&n,&m,&limit);
for(int i=0; i<n; i++)
scanf("%s",mp[0][i]);
for(int i=0; i<n; i++)
scanf("%s",mp[1][i]);
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
if(mp[0][i][j]=='#'&&mp[1][i][j]=='#')
mp[0][i][j]=mp[1][i][j]='*';
if(mp[0][i][j]=='#'&&mp[1][i][j]=='*')
mp[0][i][j]=mp[1][i][j]='*';
if(mp[0][i][j]=='*'&&mp[1][i][j]=='#')
mp[0][i][j]=mp[1][i][j]='*';
}
}
memset(vis,0,sizeof(vis));
if(bfs()) puts("YES");
else puts("NO");
}
return 0;
}
HDU 2102 A计划 (三维的迷宫BFS)的更多相关文章
- HDU 2102 A计划(三维BFS)
这题太欢乐了......虽然wa了几次,但是想到骑士在两幅图的传送门中传来传去就觉得这骑士太坑了 #include <cstdio> #include <iostream> # ...
- hdu 2102 A计划 具体题解 (BFS+优先队列)
题目链接:pid=2102">http://acm.hdu.edu.cn/showproblem.php?pid=2102 这道题属于BFS+优先队列 開始看到四分之中的一个的AC率感 ...
- HDU 2102 A计划(两层地图加时间限制加传送门的bfs)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others) Me ...
- hdu 2102 A计划
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
- HDU 2102 A计划(BFS/DFS走迷宫)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- HDU 2102 A计划【三维BFS】
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissio ...
- hdu - 2102 A计划 (简单bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...
- hdu 2102 A计划(双层BFS)(具体解释)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...
- [HDU 2102] A计划(搜索题,典型dfs or bfs)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 用typename和template消除歧义
- [Poi] Build a Vue App with Poi
Poi uses the Vue babel presets by default, so there is no additional install required to get up-and- ...
- 多校第十场1009 CRB and String题解
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给你两个字符串s和t,你能够在字符串s中随意选一个字符c,在该字符c后插入一个字符d(d! ...
- SharePoint Search之(五)Query spelling correction— 查询拼写纠正
Query spelling correction 在使用搜索引擎的时候.假设一不小心输入错误,或者对于某个词语记得不太清楚,搜索引擎会自己主动纠正: 这个功能可以缩短用户的时间,很好用.在Sh ...
- 《AndroidStudio每日一贴》11. 重构之提炼为常量
提炼为常量是从暂时变量高速提炼出静态常量,这也是我们经常使用的重构手段. 很多其它有用技巧请查看<AndroidStudio有用指南> 操作步骤: ➤ 菜单条: Refactor -> ...
- PHP获取文件大小
通过filesize函数可以取得文件的大小,文件大小是以字节数表示的. $filename = '/data/webroot/usercode/code/resource/test.txt'; $si ...
- nginx下修改svn配置
最近公司的SVN服务器地址做了变更,而我用的操作系统是Ubuntu操作系统,我也不想把以前下载的代码重新进行修改,我想通过修改svn地址,应该可以,终于在网上通过查找资料,找到了解决的方法: ...
- 判断控件的CGRect是否重合,获取控件的最大XY值
判断给定的点是否被一个CGRect包含: BOOL contains = CGRectContainsPoint(CGRect rect, CGPoint point); 判断一个CGRect是否和另 ...
- SFINAE 模板替换失败而非报错的应用
体会这一个例子,检查是否是一个类:P187
- 为什么我们须要复杂的password
前两天我打开邮箱一看.收到公司1331一封要求改动邮箱password的邮件. 为什么我们须要一个复杂的password呢?尽管我一直以来设置的password都非常复杂.可是公司这次要求改动pass ...