码迷,mamicode.com
首页 > 其他好文 > 详细

Tempter of the Bone

时间:2014-05-25 19:46:22      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   c   code   

Tempter of the Bone

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 31   Accepted Submission(s) : 3

Font: Times New Roman | Verdana | Georgia

Font Size:  

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.

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

Author

ZHANG, Zheng

Source

ZJCPC2004
bubuko.com,布布扣
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int Len_X,Len_Y,D,SIGN;
 4 int End_x,End_y;
 5 char Map[100][100];
 6 int DFS(int x,int y,int d,int D)
 7 {
 8     if(SIGN==1)return 1;
 9     if(x==End_x&&y==End_y&&d==D){SIGN+=1;return 1;}
10     if(Map[x][y]==X)return 0;
11     else Map[x][y]=X;
12     if(d>=D) {return 0;}
13     if(x+1<Len_X&&Map[x+1][y]!=X)
14     {
15         DFS(x+1,y,d+1,D);
16         Map[x+1][y]=.;
17     }
18     if(x-1>=0&&Map[x-1][y]!=X)
19     {
20         DFS(x-1,y,d+1,D);
21         Map[x-1][y]=.;
22     }
23     if(y+1<Len_Y&&Map[x][y+1]!=X)
24     {
25         DFS(x,y+1,d+1,D);
26         Map[x][y+1]=.;
27     }
28     if(y-1>=0&&Map[x][y-1]!=X)
29     {
30         DFS(x,y-1,d+1,D);
31         Map[x][y-1]=.;
32     }
33     return 0;
34 }
35 
36 int main()
37 {
38     int Begin_x,Begin_y,i,j,flat,A,B;
39     while(scanf("%d%d%d",&Len_X,&Len_Y,&D)!=EOF)
40     {
41         if(Len_X==0&&Len_Y==0&&D==0)return 0;
42         getchar();
43         for(i=0;i<Len_X;i++)
44         {
45             for(j=0;j<Len_Y;j++)
46             {
47                 scanf("%c",&Map[i][j]);
48                 if(Map[i][j]==S)
49                 {Begin_x=i;Begin_y=j;}
50                 if(Map[i][j]==D)
51                 {End_x=i;End_y=j;}
52             }
53             getchar();
54         }
55         SIGN=0;
56         A=(End_y-Begin_y)>0?(End_y-Begin_y):-(End_y-Begin_y);
57         B=(End_x-Begin_x)>0?(End_x-Begin_x):-(End_x-Begin_x);
58         if(D%2==(A+B)%2)
59             DFS(Begin_x,Begin_y,0,D);
60         if(SIGN!=0)
61             printf("YES\n");
62         else
63             printf("NO\n");
64     }
65     return 0;
66 }
View Code

 

Tempter of the Bone,布布扣,bubuko.com

Tempter of the Bone

标签:des   style   class   blog   c   code   

原文地址:http://www.cnblogs.com/LWF5201314614/p/3750332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!