Tempter of the bone
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 68206 accepted submission (s): 18719
Problem descriptionthe doggie found a bone in an alert ent maze, which fascinated him a lot. however, when he picked it up, the maze began to shake, and the doggie cocould 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 wocould 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 cocould move one block to one of the upper, lower, left and right neighboring blocks. once he entered a block, The ground of this block wocould start to sink and disappear in the next second. he coshould not stay at one block for more than one second, nor coshould he move into a visited Block. can the Poor doggie keep ve? 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 have ve, or "no" otherwise.
Sample input4 4 5s. X... XD... 3 4 5s. X... D0 0 0
Sample outputnoyes
That is, the dog needs to find a path at the door in the specified steps. Each step is 1 s.
This question has been written several times wa, and later I found that I still don't have the necessary pruning skills. I learned a lot about the online code, but still wa, the Code is even the same as Wa, I did not find any difference after I checked it for a long time. I found the input problem later. I used scanf ("% C", & map [I] [J]). besides, I have also handled the buffer issue. The input will be over later. Next time I encounter this character input, I will prefer cin.
Code:
# Include <stdio. h> # include <stdlib. h ># include <iostream> using namespace STD; char map [10] [10]; int n, m, Mark, step, finishx, finishy; int dir [4] [2] = {0,-1, 0, 1, 1, 0,-1, 0}; void DFS (INT startx, int starty, int counting) {int temp, X, Y; If (startx <1 | startx> N | starty <1 | starty> m) return; if (startx = finishx & starty = finishy & counting = step) {mark = 1; return;} temp = (step-countin G)-ABS (startx-finishx)-ABS (starty-finishy); // determines whether the number of remaining steps is an even number or greater than 0 if (temp <0 | temp & 1) return; For (INT I = 0; I <4; I ++) {x = startx + dir [I] [0]; y = starty + dir [I] [1]; If (Map [x] [Y]! = 'X') {map [x] [Y] = 'X'; DFS (X, Y, counting + 1); If (Mark) return; map [x] [Y] = '. ';}} return;} int main () {int startx, starty, wall; while (scanf ("% d", & N, & M, & step )! = EOF) {If (n = 0 & M = 0 & step = 0) break; Mark = 0; wall = 0; For (INT I = 1; I <= N; I ++) {// getchar (); For (Int J = 1; j <= m; j ++) {// scanf ("% C", & map [I] [J]); CIN> map [I] [J]; // pay attention to this pitfall, use CIN if (Map [I] [J] = 's') {startx = I; starty = J ;} if (Map [I] [J] = 'D') {finishx = I; finishy = J;} If (Map [I] [J] = 'X ') wall ++ ;}}if (M * n-wall <= step) {printf ("NO \ n"); Continue ;} map [startx] [starty] = 'X'; DFS (startx, starty, 0); If (Mark) printf ("Yes \ n "); else printf ("NO \ n");} return 0 ;}