Hdu 3345 War Chess (bfs + priority queue)

Source: Internet
Author: User

Hdu 3345 War Chess (bfs + priority queue)

War Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1732 Accepted Submission (s): 416


Problem DescriptionWar chess is hh's favorite game:
In this game, there is an N * M battle map, and every player has his own Moving Val (MV ). in each round, every player can move in four directions as long as he has enough MV. to simplify the problem, you are given your position and asked to output which grids you can arrive.

In the map:
"Y' is your current position (there is one and only one Y in the given map ).
'.' Is a normal grid. It costs you 1 MV to enter in this gird.
'T'is a tree. It costs you 2 MV to enter in this gird.
'R' is a river. It costs you 3 MV to enter in this gird.
'#' Is an obstacle. You can never enter in this gird.
'E' s are your enemies. you cannot move your SS your enemy, because once you enter the grids which are adjacent with 'e', you will lose all your MV. here "adjacent" means two grids share a common edge.
'P' are your partners. you can move your SS your partner, but you cannot stay in the same grid with him final, because there can only be one person in one grid. you can assume the Ps must stand on '. '. so, it also costs you 1 MV to enter this grid.
InputThe first line of the inputs is T, which stands for the number of test cases you need to solve.
Then T cases follow:
Each test case starts with a line contains three numbers N, M and MV (2 <= N, M <= 65536, 0 <= MV <=) which indicate the size of the map and Y's MV. then a N * M two-dimen1_array follows, which describe the whole map.
OutputOutput the N * M map, using '*'s to replace all the grids 'y' can arrive (cannot the 'y' grid itself). Output a blank line after each case.
Sample Input
53 3 100....E...Y5 6 4..........PR..E.PY...ETT....TT2 2 100.EEY5 5 2.......P...PYP...P.......3 3 1.E.EYE...

Sample Output
....E*.*Y...***..**P*..E*PY...E**....T*.EEY..*...*P*.*PYP*.*P*...*...E.EYE.*.

Authorsh

Bfs + priority queue, not optimized at the beginning, decisive timeout, the second time because of the Priority symbol TLE !! (Remember something really hard)

Use the mark array to record the MV value size of the point. The value is initialized to zero. The value is updated only when the music value increases from a point to the current point; when you enter the queue, check whether the music video value is greater than zero. If the music video value is greater than zero, you can enter the queue.

Specific Code:

# Include "stdio. h "# include" string. h "# include" queue "# include" vector "# include" algorithm "using namespace std; # define N 105 # define max (a, B) (a> B? A: B) int mark [N] [N], n, m, v; int dir [4] [2] = {, 0,-1, 1, 0}; char str [N] [N]; struct node {int x, y, d; friend bool operator <(node a, node B) {return. d
 
  
= 0 & x
  
   
= 0 & y
   
    
Q; node cur, next; cur. x = x; cur. y = y; cur. d = v; q. push (cur); memset (mark,-1, sizeof (mark); mark [x] [y] = v; while (! Q. empty () {cur = q. top (); q. pop (); for (I = 0; I <4; I ++) {next. x = dir [I] [0] + cur. x; next. y = dir [I] [1] + cur. y; if (judge (x, y) {if (str [x] [y] = '. '| str [x] [y] = 'P') t = cur. d-1; else if (str [x] [y] = 'T') T = cur. d-2; else if (str [x] [y] = 'R') t = cur. d-3; else t =-1; if (OK (x, y) & t> 0) t = 0; // reduce the combat power to 0 if (t> 0 & t> mark [x] [y]) {next. d = t; q. push (next);} mark [x] [y] = max (mark [x] [y], t) ;}}} int main () {int T, i, j; scanf ("% d", & T); while (T --) {scanf ("% d", & n, & m, & v); for (I = 0; I
    
     
= 0) {if (str [I] [j]! = 'P' & str [I] [j]! = 'Y') printf ("*"); else printf ("% c", str [I] [j]);} else printf ("% c ", str [I] [j]);} puts ("");} puts ("");} return 0 ;}
    
   
  
 

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.