Tempter of the Bonetime limit:2000/1000ms (java/other) Memory limit:65536/32768k (Java/other) total submission (s): 1 5 Accepted Submission (s): 9font:times New Roman | Verdana | Georgiafont Size:←→problem 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 is a trap, and he tried desperately to get out of this maze.
The maze is a rectangle with sizes N by M. There is a door in the maze. At the beginning, the door is 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 in 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 on 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 all test case contains three integers n, m, and T (1 < N, m < 7; 0 < T <), which denote The sizes of the maze and the time at which the door would open, respectively. The next N lines give the maze layout, with all 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 is a not-to-be processed. Outputfor each test case, print on one line "YES" if the doggie can survive, or "NO" otherwise. Sample Input
4 4 5S. X... X... Xd.... 3 4 5S. X... X.... D0 0 0
Sample Output
NOYES
Authorzhang, ZhengSourceZJCPC2004
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>using namespacestd;intdr[4][2]={{1,0},{0,1},{-1,0},{0,-1}};intf[Ten][Ten];Charmp[Ten][Ten];intsx,sy,tx,ty,t,n,m,i,j;intCheckintXinty) { if(x>=0&& x<n && y>=0&& y<m && mp[x][y]!='X'&&!f[x][y])return 1; Else return 0;}intDfsintXintYintTime ) { if(time==0&& x==tx && y==ty)return 1; for(intI=0;i<4; i++) { intxx=x+dr[i][0]; intyy=y+dr[i][1]; if(check (xx,yy)) {F[xx][yy]=1; if(Dfs (xx,yy,time-1))return 1; F[XX][YY]=0; } } return 0;}intMain () { while(SCANF ("%d%d%d", &n,&m,&t) && n!=0) { for(i=0; i<n;i++) {scanf ("%s",&Mp[i]); for(j=0; j<m;j++) if(mp[i][j]=='S') sx=i,sy=J; Else if(mp[i][j]=='D') tx=i,ty=J; } if(t==0) { if(Sx!=tx && sy!=ty) printf ("no\n"); Else if(Sx==tx && sy==ty) printf ("yes\n"); Continue; } if(ABS (TX-SX) +abs (ty-sy) >t | | (T-abs (TX-SX)-abs (ty-sy))%2!=0) {printf ("no\n");Continue;} Memset (F,0,sizeof(f)); F[sx][sy]=1; if(Dfs (SX,SY,T)) printf ("yes\n"); Elseprintf"no\n"); } return 0;}
HDU 1010 Temper of the bone (deep Search + pruning)