FZU 1046 Tempter of the Bone
来源:互联网 发布:扬州网络电视台节目单 编辑:程序博客网 时间:2024/06/06 00:48
Tempter of the Bone
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.
'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.
4 4 5S.X...X...XD....3 4 5S.X...X....D0 0 0
NOYES
#include<stdio.h>#include<string.h>#include<math.h>char map[50][50];int book[50][50];int x,y,n,m,flag,t;int dis[4][2]= {0,1,1,0,0,-1,-1,0};void dfs(int a,int b,int step){ if(map[a][b]=='D'&&step==t) { flag=1; return ; } int i,term1,term2; if(step>=t) return ; term1=abs(x-a)+abs(y-b); term2=t-step-term1; if(term1%2!=(t-step)%2||flag||term2<0) return ; for(i=0; i<4; i++) { int tx=a+dis[i][0]; int ty=b+dis[i][1]; if(!book[tx][ty]&&tx>=0&&ty>=0&&tx<n&&ty<m&&map[tx][ty]!='X') { book[tx][ty]=1; dfs(tx,ty,step+1); book[tx][ty]=0; } }}int main(){ while(~scanf("%d %d %d",&n,&m,&t),(n+m+t)) { int a,b,i,j; flag=0; memset(book,0,sizeof(book)); for(i=0; i<n; i++) { scanf("%s",map[i]); for(j=0; j<m; j++) if(map[i][j]=='S') a=i,b=j; else if(map[i][j]=='D') x=i,y=j; } book[a][b]=1; dfs(a,b,0); if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}
阅读全文
0 0
- FZU 1046 Tempter of the Bone
- FZU 1046 Tempter of the Bone
- FZU 1046 Tempter of the Bone
- 1046 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
- Mybatis的selectKey——xml映射和注解映射sql
- C++ vector简单使用
- 【设计】RESTful API的十个最佳实践
- 《招聘一个靠谱的iOS》面试题及参考答案(上)--转
- display:none与visible:hidden的区别
- FZU 1046 Tempter of the Bone
- Linux环境下Strom单机安装详解
- 数组归并排序
- 利用结巴分词的Python版本实现分词并统计词频
- Android Glide图片加载框架详解
- stm32 rtc 误差实验
- Codeforces Round #423 C. String Reconstruction
- IIS应用程序池自动回收问题的有效解决办法
- Java 常用的时间算法 返回时间集合 时间差 返回加N天后的日期 判断是否同一天