HDU1010-Tempter of the Bone
2016-04-28 20:27
211 查看
A - Tempter of the Bone
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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.
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.
Output
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
Sample Input
Sample Output
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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.
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.
Output
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
Sample Input
4 4 5 S.X. ..X. ..XD .... 3 4 5 S.X. ..X. ...D 0 0 0
Sample Output
NO YES
#include <stdio.h> #include <stdlib.h> #include <math.h> char map[9][9]; int n,m,t; int di,dj,escape; int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}}; void dfs(int si,int sj,int cnt) { int i,temp; if(si>n||sj>m||si<=0||sj<=0) return; if(si==di&&sj==dj&&cnt==t) { escape=1;return; } if(escape) return; temp=(t-cnt)-abs(si-di)-abs(sj-dj); if(temp<0||temp%2) return; for(i=0;i<4;i++) { if(map[si+dir[i][0]][sj+dir[i][1]]!='X') { map[si+dir[i][0]][sj+dir[i][1]]='X'; dfs(si+dir[i][0],sj+dir[i][1],cnt+1); map[si+dir[i][0]][sj+dir[i][1]]='.'; } } } int main() { int i,j; int si,sj; while(~scanf("%d%d%d",&n,&m,&t)) { if(n==0&&m==0&&t==0) break; int wall=0; char temp; scanf("%c",&temp); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%c",&map[i][j]); if(map[i][j]=='S') {si=i;sj=j;} else if(map[i][j]=='D') {di=i;dj=j;} else if(map[i][j]=='X') wall++; } scanf("%c",&temp); } if(n*m-wall<=t) { printf("NO\n");continue; } escape=0; map[si][sj]='X'; dfs(si,sj,0); if(escape) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- Git学习7:Git中的里程碑
- 测试基于gtid模式主从复制下数据不一致的处理
- 0428-项目再开发2.0
- C++学习笔记之七 复合类型---枚举
- Dubbo之旅--注册中心
- Android最佳性能实践(一)——合理管理内存
- map映照容器
- 用PHP写自定义的简单WEB服务器
- 作品展示打分表
- 第七周 周记
- 我的Android进阶之旅------>解决Jackson等第三方转换Json的开发包在开启混淆后转换的实体类数据都是null的bug
- Java虚拟机 运行时数据区
- Dos.orm入门遇到的问题总结
- 采用calyer画多边形
- gravity与Layout_gravity的区别
- android.textiview.settextcolor失效的问题
- 笔记三:const 在变量、函数、指针中的使用
- Fragment的setUserVisibleHint详解
- dao
- python学习4