hdu 1010 Tempter of the Bone 解题报告
来源:互联网 发布:非网络rpg手机游戏 编辑:程序博客网 时间:2024/06/05 13:39
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 61015 Accepted Submission(s): 16696
Problem Description
The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.
The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
Input
The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following:
'X': a block of wall, which the doggie cannot enter;
'S': the start point of the doggie;
'D': the Door; or
'.': an empty block.
The input is terminated with three 0's. This test case is not to be processed.
'X': a block of wall, which the doggie cannot enter;
'S': the start point of the doggie;
'D': the Door; or
'.': an empty block.
The input is terminated with three 0's. This test case is not to be processed.
Output
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
Sample Input
4 4 5S.X...X...XD....3 4 5S.X...X....D0 0 0
Sample Output
NOYES解题思路DFS解题代码:#include <iostream>#include <stdio.h>#include <cstring>#include <cmath>using namespace std;int n,m,t,dx,dy,ex,ey,flag;char map[10][10];int d[4][2]= {0,1,0,-1,-1,0,1,0};void dfs(int x,int y,int t){ if(flag==1) return ; if(x==ex&&y==ey&&t==0) { flag=1; return ; } if(t==0) return ; else { for(int i=0; i<4; i++) { int nx=x+d[i][0]; int ny=y+d[i][1]; if(nx>=0 && nx<n && ny>=0 && ny<m && map[nx][ny]!='X' ) { map[nx][ny]='X';//走过就标记 dfs(nx,ny,t-1); map[nx][ny]='.';//回溯 } } }}int main(){ while(scanf("%d%d%d",&n,&m,&t)!=EOF) { if(n==0 && m==0 && t==0) return 0; for(int i=0; i<n; i++) scanf("%s",map[i]); for(int i=0; i<n; i++) for(int j=0; j<m; j++) { if(map[i][j]=='S') { dx=i; dy=j; } if(map[i][j]=='D') { ex=i; ey=j; } } flag=0; map[dx][dy]='X'; if(((ex+ey-dx-dy)-t)%2==0)//剪枝 { dfs(dx,dy,t); } if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- HDU 1010 Tempter of the Bone 解题报告
- hdu 1010 解题报告 ----Tempter of the Bone
- hdu 1010 Tempter of the Bone 解题报告
- Tempter of the Bone(HDU 1010)解题报告
- hdu 1010 Tempter of the Bone 解题报告
- 【解题报告】hdu1010 Tempter of the Bone
- HDOJ 1010 Tempter of the Bone解题报告
- HDOJ 1010:Tempter of the Bone 迷宫问题 解题报告
- HDU - 1010 Tempter of the Bone 深搜模板题(DFS)解题报告
- hdu 1010 Tempter of the Bone dfs搜索 奇偶剪枝 解题报告
- HDU1010 Tempter of the Bone 解题报告--dfs
- HDU 1010 Tempter of the Bone
- 迷宫 hdu 1010 Tempter of the Bone
- HDU 1010-Tempter of the Bone
- hdu 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- HDU 1010 Tempter of the Bone
- hdu 1010 Tempter of the Bone(深搜)
- 大规模集成电路机
- C语言浮点数运算,讲述原理并总结一些案例
- 美国国防部战略:大规模、分布式,构建数字化防御体系
- uc_day06
- 顺序容器:vector的自增长特性
- hdu 1010 Tempter of the Bone 解题报告
- Android使用XML Shape绘制带阴影效果的圆形按钮
- 下载的文件需要右键属性解除锁定的一次性解决方法
- 计算机是由硬件系统
- 通过重写ViewGroup学习onMeasure()和onLayout()方法
- ubuntu 下安装配置 tomcat
- Remove Element
- JSP session权限创建、检查、退出
- CPU即中央处理器