hdu2102
版权声明:本文为博主原创文章。未经博主同意不得转载。 https://blog.csdn.net/u014303647/article/details/27705195
题目链接:
pid=2102" rel="nofollow">http://acm.hdu.edu.cn/showproblem.php? pid=2102
题目:
A计划
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8731 Accepted Submission(s): 2076
年迈的国王正是心急如焚。告招天下勇士来解救公主。
只是公主早已习以为常。她深信智勇的骑士LJ肯定能将她救出。
现据密探所报,公主被关在一个两层的迷宫里。迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示。墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到还有一层的相对位置,但假设被转到的位置是墙的话,那骑士们就会被撞死。
骑士们在一层中仅仅能前后左右移动,每移动一格花1时刻。
层间的移动仅仅能通过时空传输机。且不须要不论什么时间。
T如上所意。接下去的前N*M表示迷宫的第一层的布置情况。后N*M表示迷宫第二层的布置情况。
5 5 14
S*#*.
.#...
.....
****.
...#.
..*.P
#.*..
***..
...*.
*.#..
pid=1728" rel="nofollow" style="color:rgb(26,92,200);text-decoration:none;">1728
1175 2717这个题目我最開始用数组维护。。
。可是一直错。我也不知道在哪里wa了。。。
所以改用标记数组。。。
用bfs。
。。。
最開始的时候须要预处理一下.。。。
。
1:假设两个对面都是传送门则会出现死循环。
。。
所以要把这两面设置成墙。
。
。
2:假设传送门的对面是墙 。则两个设为墙。
。。
。
然后就是bfs了。。
。
</pre><pre code_snippet_id="370769" snippet_file_name="blog_20140530_2_5736025" name="code" class="css">#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
struct node
{
int x,y;
int step;
int a;
}start;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int n,m,T,ex,ey,ez;
char map[2][15][15];
bool bfs()
{
start.x=0,start.y=0, start.a=0, start.step=0;
node first,next;
queue<node>q;
map[0][0][0]='*';
q.push(start);
while(!q.empty())
{
first=q.front();
q.pop();
if(first.step>T) break;
if(first.x==ex&&first.y==ey&&first.a==ez&&first.step<=T)
return true;
for(int i=0; i<4; i++)
{
next=first;
next.x+=dx[i];
next.y+=dy[i];
++next.step;
if(next.x<0||next.x>=n||next.y<0||next.y>=m) continue;
if(map[next.a][next.x][next.y]=='#')
{
map[next.a][next.x][next.y]='*';
next.a=(next.a==1)?0:1;
q.push(next);
}
if(map[next.a][next.x][next.y]=='.')
{
map[next.a][next.x][next.y]='*'; q.push(next);
}
if(next.a==ez&&next.x==ex&&next.y==ey&&next.step<=T)
return true;
}
}
return false;
}
int main()
{
char str[25];
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&T);
for(int k=0;k<2;k++)
for(int i=0;i<n;i++)
{
scanf("%s",str);
for(int j=0;j<m;j++)
{
map[k][i][j]=str[j];
if(map[k][i][j]=='P')
ez=k,ex=i,ey=j;
}
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(map[0][i][j]=='#'&&map[1][i][j]=='#'){ map[0][i][j]='*';map[1][i][j]='*';}
if(map[0][i][j]=='*'&&map[1][i][j]=='#'){ map[0][i][j]='*';map[1][i][j]='*';}
if(map[0][i][j]=='#'&&map[1][i][j]=='*'){ map[0][i][j]='*';map[1][i][j]='*';}
}
if(bfs())
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
hdu2102的更多相关文章
- A计划 hdu2102(BFS)
A计划 hdu2102 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国 ...
- HDU2102 A计划
解题思路:一道简单题,却WA了十几发,犯几个低级错误.还是不能急躁, 内心要平静,具体分析见代码: #include<iostream> #include<cstdio> ...
- hdu2102(bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 分析:bfs求最短时间到达'P'点,不过本题有好几个trick,我都踩到了,自己还是太嫩了... ...
- A计划 hdu2102(bfs一般题)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- Hdu2102 A计划 2017-01-18 14:40 60人阅读 评论(0) 收藏
A计划 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- HDU2102(KB2-I)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu2102 BFS
这是一道BFS的搜索题目,只是搜索范围变为了三维.定义数组visit[x][y][z]来标记空间位置,x表示楼层,y和z表示相应楼层的平面坐标. #define _CRT_SECURE_NO_DEPR ...
- HDU2102 A计划 —— BFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others) Me ...
- 搜索专题: HDU2102 A计划
这不知道是公主被抓走了第几次了,反正我们的骑士救就对了(别说了,我都救我都救...);这次的迷宫有些特别,双层,带电梯(?),而且这个电梯还有生命危险,可能会撞死(一层是电梯,一层是墙),或者永远困在 ...
随机推荐
- javascript Function类型
Function(函数)类型实际上是对象,每个函数都是Function类型的实例,而且都与其他引用类型一样具有属性和方法,由于函数是对象,因此函数名实际上也是一个指向函数对象的指针 声明方式 func ...
- C# 使用/配置Log4Net
1.首先在项目中添加Nuget程序包... 2.然后在NuGet窗体中搜索Log4Net,然后点击安装<安装过程可能会持续几分钟,请耐心等待> 3.在项目中添加一个Config文件,如已有 ...
- Eclipse软件使用说明
http://www.ziqiangxuetang.com/eclipse/eclipse-explore-menus.html
- VIM命令图解
右键在新窗口打开查看大图 删除所有:dG 来源见水印
- Eclipse的版本命名
Eclipse自3.1开始使用木星的卫星作为版本名,例如: 木卫一:伊奥 lo木卫二:欧罗巴 Europa木卫三:伽倪墨得斯 Ganymede木卫四:卡利斯托 Callisto .... Eclips ...
- when coding in a fresh system
I have designed a component of a web system with my workmate. In detail, I am just a coder instead o ...
- JAVA成员方法的调用分析
如下面例子: public class A { int x=10; public int getx() {return x;} } public class B extends A { int x=2 ...
- Code Signal_练习题_commonCharacterCount
Given two strings, find the number of common characters between them. Example For s1 = "aabcc&q ...
- python中垃圾回收机制
Python垃圾回收机制详解 一.垃圾回收机制 Python中的垃圾回收是以引用计数为主,分代收集为辅.引用计数的缺陷是循环引用的问题.在Python中,如果一个对象的引用数为0,Python虚拟 ...
- cf605D. Board Game(BFS 树状数组 set)
题意 题目链接 有\(n\)张牌,每张牌有四个属性\((a, b, c, d)\),主人公有两个属性\((x, y)\)(初始时为(0, 0)) 一张牌能够被使用当且仅当\(a < x, b & ...