Advertisement
steverobinson

Puzzle: Warring Civilizations

Mar 23rd, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. Problem code: WAGE
  2. ----------------------------
  3.  
  4. Danny has created a new civilization on a 2D grid. At the outset each grid location may be occupied by one of three life forms: Woods, Axe, or Grass. Each day, differing life forms occupying horizontally or vertically adjacent grid locations wage war. In each war, Woods always defeat Axe, Axe always defeat Grass, and Grass always defeat Woods. At the end of the day, the winner expands its territory to include the loser's grid position. The loser vacates the position.Determine the territory occupied by each life form after n days.
  5.  
  6. Input
  7.  
  8. The first line of input contains t, the number of test cases. Each test case begins with three integers not greater than 100: r and c, the number of rows and columns in the grid, and n. The grid is represented by the r lines that follow, each with c characters. Each character in the grid is W, A, or G, indicating that it is occupied by Woods, Axe, or Grass respectively.
  9.  
  10. Output
  11.  
  12. For each test case, print the grid as it appears at the end of the nth day.
  13.  
  14. Example
  15.  
  16. Input:
  17. 2
  18. 3 3 1
  19. WWW
  20. WAW
  21. WWW
  22. 3 4 2
  23. WAGW
  24. AGWA
  25. GWAG
  26.  
  27.  
  28. Output:
  29. WWW
  30. WWW
  31. WWW
  32.  
  33. WWWA
  34. WWAG
  35. WAGW
  36.  
  37. <<---Solution Found: For help contact steve_robinson@live.com || stevanity.hf@gmail.com--->>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement