Блог пользователя stould

Автор stould, 9 лет назад, По-английски

I was trying to solve the following problem:Death Row

I spent the whole morning trying to solve it, but just wrong answer.. I just realized that the minimum time that he and his family still living is when Yama at every visit, kills M people and (N-M) >= 2, and when is remaining just N = 2 people, Yama need to visit more two times. I guess it is right, but I'm receiving wrong answer..

Can someone help me ? Thanks in advance.

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

If I understood the problem correctly then this is the solution:

If n ≤ 3 then answer is n

else if n is even then answer is 3

else answer is 4.

Reasoning is trivial.

  • »
    »
    9 лет назад, # ^ |
    Rev. 5   Проголосовать: нравится +5 Проголосовать: не нравится

    I used this strategy but I do not check when N is even (the answer is 3 intead of 4). Can you explain it to me ?

    Thank you.

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      From what I understood the you can either reduce a number by one or reduce a number to some non-trivial factor of itself.

      For all even numbers reduce it to 2 in its first step and then take 2 steps to get to 0.

      For all odd numbers subtract 1 on first step to make it even, then take 3 steps to get to 0.