HDU 1010 Tempter of the Bone

Source: Internet
Author: User

Topic Connection

http://acm.hdu.edu.cn/showproblem.php?pid=1010

Tempter of the Bonedescription

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 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.

Input

The 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.

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

started with BFS write WA dropped, point open discus and then use DFS write Tle%>_<%. Check the information found there are odd and even pruning this thing, knock on OK.

Parity pruning See Niang.

http://baike.baidu.com/history/%E5%A5%87%E5%81%B6%E5%89%AA%E6%9E%9D/76619083

1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <queue>8#include <map>9 usingStd::abs;Ten usingstd::cin; One usingstd::cout; A usingStd::endl; - usingStd::find; - usingStd::sort; the usingStd::map; - usingstd::p air; - usingStd::queue; - usingstd::vector; + usingStd::multimap; - #definePB (E) push_back (e) + #defineSZ (c) (int) (c). Size () A #defineMP (A, b) Make_pair (A, B) at #defineAll (c) (c). Begin (), (c). End () - #defineITER (c) Decltype ((c). Begin ()) - #defineCLS (arr,val) memset (arr,val,sizeof (arr)) - #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) - #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) in Const intN =Ten; -typedef unsignedLong Longull; to BOOLVis[n][n]; + CharG[n][n]; - intH, W, T, Sx, Sy, Dx, Dy; the Const intDx[] = {0,0, -1,1}, dy[] = {-1,1,0,0 }; * BOOLDfsintXintYints) { $     //find a solution and return directlyPanax Notoginseng     if(s = = T && x = = Dx && y = Dy)return true; -     intTMP = ABS (X-DX) + ABS (Y-DY)-ABS (T-s); the     //The current position to the end point takes more time than the rest of the time +     //parity pruning, the start and end points determine the number of steps to be left is odd or even (no this will time out the drop%>_<%) A     if(tmp >0|| TMP &1)return false; theRep (I,4) { +         intNX = x + dx[i], NY = y +Dy[i]; -         if(NX <0|| NX >= H | | NY <0|| NY >= W)Continue; $         if(Vis[nx][ny] | | G[nx][ny] = ='X')Continue; $Vis[nx][ny] =true; -         if(Dfs (NX, NY, S +1))return true; -Vis[nx][ny] =false; the     } -     return false;Wuyi } the intMain () { - #ifdef LOCAL WuFreopen ("In.txt","R", stdin); -Freopen ("OUT.txt","w+", stdout); About #endif $      while(~SCANF (" %d%d%d", &h, &w, &t) && H + W +T) { -         inttot =0; - Rep (i, H) { -scanf"%s", G[i]); A Rep (J, W) { +VIS[I][J] =false; the                 if(G[i][j] = ='S') Sx = i, Sy =J; -                 if(G[i][j] = ='D') Dx = i, Dy =J; $                 if(G[i][j] = ='X') tot++; the             } the         } the         //can walk the number of lattice less than the time, direct non-compliance, no longer search the         if(H * W-tot <= T) {Puts ("NO");Continue; } -Vis[sx][sy] =true; inPuts (Dfs (Sx, Sy,0) ?"YES":"NO"); the     } the     return 0; About}
View Code

HDU 1010 Tempter of the Bone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.