杭电1010
来源:互联网 发布:3g模型 淘宝 编辑:程序博客网 时间:2024/04/30 10:55
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 65276 Accepted Submission(s): 17822Problem DescriptionThe 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.InputThe 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.OutputFor each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.Sample Input4 4 5S.X...X...XD....3 4 5S.X...X....D0 0 0Sample OutputNOYES
#include<stdio.h> #include<string.h> #include<math.h>int visit[10][10],n,m,t,xx,yy,find;int dx[]={0,0,1,-1},dy[]={1,-1,0,0}; char map[10][10]; void dfs(int a,int b ,int T ) { int f,k; if(find==1) return; if(T==t) { if(map[a][b]=='D') find=1; return; } f=abs(a-xx)+abs(b-yy); if(f+T>t) return; if(f%2!=(t-T)%2) return; for(k=0;k<4;k++) { int x=a+dx[k]; int y=b+dy[k]; if(x>=0&&x<n&&y>=0&&y<m&&map[x][y]!='X'&&visit[x][y]==0) { visit[x][y]=1; dfs(x,y,T+1); visit[x][y]=0; } } } int main() { int a,b,i,j; while(scanf("%d%d%d",&n,&m,&t)&&!(n==0&&m==0&&t==0)) { find=0; getchar(); for(a=0;a<n;a++) { for(b=0;b<m;b++) { scanf("%c",&map[a][b]); if(map[a][b]=='S') { i=a; j=b; } else if(map[a][b]=='D') { xx=a; yy=b; } } getchar(); } memset(visit,0,sizeof(visit)); visit[i][j]=1; dfs(i,j,0); if(find) printf("YES\n"); else printf("NO\n"); } }
0 0
- 杭电acm 1010
- 杭电ACM-1010
- 杭电1010
- 杭电 1010
- 杭电1010题
- 杭电1010
- 杭电1010
- 杭电1010
- 杭电 1010
- 杭电1010
- 杭电1010
- 杭电 1010
- 杭电1010
- 杭电oj 1010
- 杭电1010题
- 杭电1010
- 杭电 1006 1007 1010
- 杭电1010-奇偶剪枝
- Android Calendar添加本地账户
- Java基础学习中,关于面向对象中多态、抽象类、接口的总结
- maven项目启动报错
- Lucas–Kanade
- GridView实现多表头合并,解决表头数据对不齐
- 杭电1010
- 杭电1241 oil deposit
- 杭电1312 red and black
- poj3278 catch that cow
- 杭电1242 rescue
- hdu 1253 胜利大逃亡
- 设计模式(四)之命令模式
- 杭电1863+1879
- hdu1102 constructing road