HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


50446 - Snake

Guest
• Review clarifications (1)

Volume problems

• 50861 - The largest Student Group
• 50418 - Student averages
• 50420 - Teachers Sightseeing
• 50384 - Permutations revisited
• 50841 - My grand-grand-grandfather
• 50395 - Page "Like" Averages
• 50407 - Missing Number
• 50516 - Lines
• 50446 - Snake
• 50875 - Take m-out
• 50509 - Reading Book
• 50529 - Row to Table
• 50786 - Top Question
• 50788 - Eight Puzzle
• 50499 - Table to Row
• 50823 - Secret Number
• 50853 - Parking Place

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Snake

Your brother likes the snake game, but he is small and he cannot play the original game. You want to design a simplified version for him with the following rules:

  • Board is square matrix (n x n)
  • Snake starts the game from the upper left corner with an initial lifepoint (m). Initially, upper left corner always contains zero.
  • The size of the snake is fixed 1x1 and it doesn’t grow or shrink
  • On random positions of the board, there are different objects
    • Bonus: positive integers
    • Obstacles: negative numbers
    • Empty tiles: where snake can move freely (zero)
If the snake goes over bonuses, it’s rewarded lifepoints. If the snake goes over obstacles, it’s punished, lifepoint is decreased. After a cell visited, the bonus or the obstacle disappear from the cell (cell changes to 0). Game ends in three conditions:
  • if the snake hits to a border
  • or if its lifepoint is decreased to zero or less
  • or when the actions given are completed

Question: Write a program that reads a two dimensional board information and k movement instructions. Then your program will calculate and show the number of moves that the snake completed and the lifepoints when program ended.

Input specification
You will be given 3 integers in the first line:

  • n: the size of board
  • m: initial points that the snake has
  • k: the number of instructions given
where 1 ≤ n ≤ 25, 0 ≤ m ≤ 2000 and 1 ≤ k ≤ 100. Then, in the following n lines, you will be given n integers where each number is between -100 and +100. Then in the following k lines, you will be given k instructions. Each instruction line will have a letter (U, D, R or L) and an integer.
  • Letter: U: Up; D: Down; R: Right; or L: Left
  • an integer: the number of moves in the given direction

Output specification
Show two integers:

  1. The number of moves that the snake completed
  2. Lifepoints when the game ended

Sample Input I
5 10 5
0 4 0 0 -30
0 10 0 -15 0
-5 0 6 0 20
12 0 -9 0 0
0 0 -7 0 0
R 2
D 3
R 1
U 3
L 3
Sample Output I
8 -4

Explanation: The snake starts from the upper left corner with an initial lifepoint, 10.

  • It goes two right and collects 4 points: 14 lifepoints
  • Then it goes three down: collects 6 points and punished 9 points: 11 lifepoints
  • It goes 1 right
  • It goes 2 up: the lifepoint decreases to -4
game ends because the lifepoints gets less than zero.



Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.

www.contester.ru