hdu 1010 Tempter of the Bone
来源:互联网 发布:淘宝历史宝贝如何上架 编辑:程序博客网 时间:2024/05/27 21:49
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 50008 Accepted Submission(s): 13420
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
Author
ZHANG, Zheng
Source
ZJCPC2004
Recommend
JGShining
迷宫题。经典的奇偶剪枝。
#include<stdio.h>#include<string.h>int dx[4]={0,0,-1,1};int dy[4]={1,-1,0,0};char maze[10][10];int visit[10][10];int sx,sy,ex,ey,n,m,t;int abs(int x){ return x<0?-x:x;}int dfs(int x,int y,int step){ int i,nx,ny,temp; if(x==ex&&y==ey&&step==t) return 1; if(step>=t) return 0; temp=t-abs(ex-x)-abs(ey-y)-step; if(temp<0||temp%2!=0)//奇偶剪枝 return 0; for(i=0;i<4;i++) { nx=x+dx[i]; ny=y+dy[i]; if(nx<0||nx>=m||ny<0||ny>=n||maze[ny][nx]=='X'||visit[ny][nx]==1) continue; visit[ny][nx]=1; if(dfs(nx,ny,step+1)) return 1; visit[ny][nx]=0; } return 0;}int main(){ int i,j,wall; while(scanf("%d%d%d",&n,&m,&t),n||m||t) { wall=0; getchar(); memset(visit,0,sizeof visit); for(i=0; i<n; i++) { scanf("%s",maze[i]); for(j=0; j<m; j++) { if(maze[i][j]=='S') { sx=j; sy=i; } else if(maze[i][j]=='D') { ex=j; ey=i; } else if(maze[i][j]=='X') { wall++; } } } if(n*m-wall<=t) { printf("NO\n"); continue; } visit[sx][sy]=1; if(dfs(sx,sy,0)) printf("YES\n"); else printf("NO\n"); } return 0;}
- 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(深搜)
- 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
- HDU 1010 Tempter of the Bone (DFS)
- hdu 1010 Tempter of the Bone
- HDU 1010 - Tempter of the Bone
- hdu 1010 Tempter of the Bone
- 又迷茫了!
- ubuntu_安装virtual_box
- linux日常命令小结
- NAND FLASH ECC校验原理与实现
- 关于换零钱损失问题的解释
- hdu 1010 Tempter of the Bone
- tlb,lib,tlh,dll
- 跨浏览器的事件对象
- Bash特定的转义符的特殊的含义
- 如何做文献综述:克雷斯威尔五步文献综述法
- shell脚本备忘
- MySQL 深入剖析 char varchar 类型,有了VARCHAR,为什么还要有CHAR?
- 介绍javascript MVC框架 ---- angular
- 安装、设置与启动MySql绿色版的方法