ivplay's blog

By ivplay, history, 5 years ago, In English
  • I am getting hard time with this problem-lightoj 1296 — Again Stone GameThere are N-piles,each pile contains max 2^31 stones. you must have to pick at least one and you can pick at most half of the stones. I have seen solutions of this problem but I still don't understand how it works :(. I will be using term SGN as Sprague-Grundy Number. If a pile has 3 stones what should be its SGN? my analysis says it should be like-
    • SGN(1)=0,
    • SGN(2)= mex(1) = 1, since we must have to take 1 stone, we have only one choice
    • SGN(3)= mex(1) = 1, since we must have to take 1 stone, we have only one choice
    • Now the solution to this problem I have seen says SGN(3) is 0 which unfortunately, I don't understand how :(
  • I have just started to learn Sprague-Grundy Number. I am looking for help to make me understanding how the calculation of SGN is defined for this problem. May be I have misunderstood the meaning of MEX defined in SGN.
 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ivplay (previous revision, new revision, compare).

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ivplay (previous revision, new revision, compare).

»
5 years ago, # |
Rev. 6   Vote: I like it 0 Vote: I do not like it

SGN(3) is zero because a pile with 3 stones is a P-position. I'd suppose "half" here is defined as floor(N / 2). Now, if you have 3 stones, then you are forced to pick one stone and end up in a position with 2 stones, which is a N-position. That's why SGN(3) = 0. In general, by definition SGN(n) = mex({SGN(n - n / 2), ..., SGN(n - 1)}). Try to find a closed form and prove it by induction. That's how this problem is supposed to be approached.

Good luck!

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    • In general, by definition SGN(n) = mex({SGN(n - n / 2), ..., SGN(n - 1)}).
    • I was making wrong moves for finding mex and that was my mistake. my definition was
    • SGN(n) = mex({SGN(n / 2), ..., SGN(1)}). which is absolutely wrong. Thanks a lot for your kind help.