ZJCPC2004 Tempter of the Bone
来源:互联网 发布:信捷p乚c编程软件下载 编辑:程序博客网 时间:2024/06/06 11:39
Tempter of the Bone
时间限制: 1000ms
内存限制: 32768KB
HDU ID: 101064位整型: Java 类名:
上一题
提交 运行结果 统计 讨论版
下一题题目描述
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.
输入
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.
输出
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
样例输入
4 4 5S.X...X...XD....3 4 5S.X...X....D0 0 0
样例输出
NOYES
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;int a,b,c,flag,book[10][10],n,m;char map[10][10];int s1[4][2]= {0,1,0,-1,1,0,-1,0};void dfs(int x,int y,int step){ if(x==n&&y==m&&step==c) { flag=1; return ; } int ans=c-step-abs(n-x)-abs(m-y); if(ans<0||ans&1) return ; for(int i=0; i<4; i++) { int tx=x+s1[i][0]; int ty=y+s1[i][1]; if(tx>=0&&tx<a&&ty>=0&&ty<b&&map[tx][ty]!='X') { if(book[tx][ty]==0) { book[tx][ty]=1; if(flag) return ; dfs(tx,ty,step+1); book[tx][ty]=0; } } } return ;}int main(){ while(scanf("%d %d %d",&a,&b,&c)&&(a+b+c)) { memset(book,0,sizeof(book)); flag=0; int i,j,k,s; for(i=0; i<a; i++) scanf("%s",map[i]); for(i=0; i<a; i++) for(j=0; j<b; j++) if(map[i][j]=='S') { k=i; s=j; } else if(map[i][j]=='D') { n=i; m=j; } if(abs(n-k)+abs(m-s)>c) printf("NO\n"); else { book[k][s]=1; dfs(k,s,0); if(flag) printf("YES\n"); else printf("NO\n"); } } return 0;}
0 0
- ZJCPC2004 Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- Tempter of the Bone
- 常用的电平标准TTL、CMOS、LVTTL、LVCMOS、ECL、PECL、LVPECL、RS232、RS485等
- Android性能优化--内存泄露
- 工作区Run
- malloc()函数详解
- List集合特有迭代器ListIterator
- ZJCPC2004 Tempter of the Bone
- C++实现对称矩阵以及压缩存储
- Android音视频点/直播模块开发实践总结
- 在服务器端取得客户端传递过来的JSON字符串,转成JSON对象并取值
- MySQL中字段varchar和int排序的区别
- ppp拨号脚本配置
- 调整tomcat 虚拟机内存大小
- 国学节选
- Android Studio若干实用的插件