A计划 HDU - 2102
A计划
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 34211 Accepted Submission(s):
8412
http://acm.hdu.edu.cn/showproblem.php?pid=2102
现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。
<= N,M <=10)。T如上所意。接下去的前N*M表示迷宫的第一层的布置情况,后N*M表示迷宫第二层的布置情况。
5 5 14
S*#*.
.#...
.....
****.
...#.
..*.P
#.*..
***..
...*.
*.#..
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std; const int maxn=+;
char map[][maxn][maxn];
int book[][maxn][maxn];
int n,m,c,t,stc,stx,sty,dec,dex,dey,flag;
int nex[][]={{,},{,},{-,},{,-}}; void dfs(int c,int x,int y,int time){
if(c==dec&&x==dex&&y==dey){
if(time<=t){
flag=;
}
return;
}
if(time>t||flag==){
return;
}
for(int i=;i<;i++){
int tx=x+nex[i][];
int ty=y+nex[i][];
if(tx<||tx>n||ty<||ty>m){
continue;
}else if(book[c][tx][ty]==){
if( (c==&&(book[][tx][ty]==||book[][tx][ty]==)) || (c==&&(book[][tx][ty]==||book[][tx][ty]==)) ){
continue;
}else{
if(c==){
book[][tx][ty]=;
dfs(,tx,ty,time+);
book[][tx][ty]=;
}else{
book[][tx][ty]=;
dfs(,tx,ty,time+);
book[][tx][ty]=;
}
}
}else if(book[c][tx][ty]==){
book[c][tx][ty]=;
dfs(c,tx,ty,time+);
book[c][tx][ty]=;
}
}
} int main(){
scanf("%d",&c);
while(c--){
scanf("%d%d%d",&n,&m,&t);
memset(book,,sizeof(book));
for(int i=;i<=;i++){
for(int j=;j<=n;j++){
getchar();
for(int k=;k<=m;k++){
scanf("%c",&map[i][j][k]);
if(map[i][j][k]=='P'){
dec=i,dex=j,dey=k;
}else if(map[i][j][k]=='*'){
book[i][j][k]=;
}else if(map[i][j][k]=='#'){
book[i][j][k]=;
}else if(map[i][j][k]=='S'){
stc=i,stx=j,sty=k;
}
}
}
getchar();
}
flag=;
book[stc][stx][sty]=;
dfs(stc,stx,sty,);
if(flag==){
printf("YES\n");
}else{
printf("NO\n");
}
}
return ;
}
A计划 HDU - 2102的更多相关文章
- I - A计划 HDU - 2102
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 2102 A计划
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
- 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计划 (简单bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...
- hdu 2102 A计划(优先队列+dfs)
改了好久,上午来实验室打出来了,运行就是不对,一直找啊找!还是没找到,最后突然停电了,打好的代码还没保存呢! 刚才来的时候又重新打了一遍!!!结果一个小小的错误wrong了好久!!! 在dfs值返回时 ...
- 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 ...
- 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)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...
随机推荐
- Anaconda+django安装问题
Anaconda使用中常遇到如下问题: 如果Anaconda不是最新版本,可在Anaconda Prompt中使用如下命令更新至最新版 conda update -n base -c defaults ...
- 连接远程MySQL数据库项目启动时,不报错但是卡住不继续启动的,
连接远程MySQL数据库项目启动时,不报错但是卡住不继续启动的, 2018-03-12 17:08:52.532DEBUG[localhost-startStop-1]o.s.beans.factor ...
- BootStrap顺序验证和指定字符个数发送请求
fields: { curPwd: { verbose: false, //代表验证按顺序验证.验证成功才会下一个(验证成功才会发最后一个remote远程验证) threshold: 6,//有6字符 ...
- 编程入门视频【 Python、PHP、ThinkPHP、Laravel、Mysql、微信小程序】
免费分享 Python.PHP.ThinkPHP.Laravel.Mysql.微信小程序等学习视频 点击进入搜刮 免费分享 Python.PHP.ThinkPHP.Laravel.Mysql.微信小程 ...
- Illegal invocation with document.querySelector [duplicate]
document.querySelectorAll赋给其它变量时, 为什么要.bind(document)? https://stackoverflow.com/questions/12637061/ ...
- 1.2低级线程处理API
并行扩展库相当有用,因为它允许使用更高级的抽象——任务,而不必直接和线程打交道.但有的时候,要处理的代码是在TPL和PLINQ问世(.NET4.0)之前写的.也有可能某个编程问题不能直接使用它们解决, ...
- Mac osx 系统安装 eclipse
https://jingyan.baidu.com/article/fea4511ad46a86f7bb9125e5.html
- jquery 第五章 jQuery操作表单与表格
1.回顾 对象.bind("事件名称",function(){ // }) 阻止冒泡事件 return false, event stopProapagation() 模拟事件 ...
- HTML5+CSS3点击指定按钮显示某些内容效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- min-max容斥 hdu 4336 && [BZOJ4036] 按位或
题解: 之前听说过这个东西但没有学 令$max(S)$表示S中编号最大的元素,$min(S)$表示编号中最小的元素 $$max(S)=\sum{T \in S} {(-1)}^{|T|+1} min( ...