CEN112 Homeworks 2013-2015 |
Старт: 15.дек.2013 в 12:00:00
Финиш: 15.дек.2013 в 17:00:00
Турнир завершён!
• Турнирная таблица
|
|
Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. 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:
- The number of moves that the snake completed
- 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.
Для отправки решений необходимо выполнить вход.
|