ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Турниры > CEN112 Homeworks 2013-2015 > задача:


15-SprHW-20. 50446 - Snake

CEN112 Homeworks 2013-2015

Старт: 15.дек.2013 в 12:00:00
Финиш: 15.дек.2013 в 17:00:00
Турнир завершён!
• Турнирная таблица

Гость
• Вопросы к жюри (1)

Задачи турнира

• 13-Fall2-20. 50395 - Page "Like" Av...
• 14-Spr1-30. 50492 - Contest Score...
• 14-Spr1-40. 50538 - Sum of kth Dia...
• 14-Spr1-60. 50647 - Спираль
• 14-Spr2-20. 50442 - Polynomial Add...
• 14-Spr2-40. 50361 - Align Two Lists
• 14-Spr2-50. 50616 - Змейка
• 14-Spr2-60. 50444 - n digit kth nu...
• 15-SprHW-20. 50446 - Snake
• 15-SprHW-30. 50788 - Eight Puzzle
• 15-SprHW-40. 50746 - Most Visited
• 15-SprHW-60. 50516 - Lines
• 15-SprPr2-20. 50509 - Reading Book
• 15-SprPr2-60. 50766 - Word Puzzle
• 15-SprPr2-80. 50786 - Top Question
• 15-SprPrE1-20. 50785 - Swimming ...
• 15-SprPrE1-40. 50748 - Gold Store

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 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:

  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