MtRock.cs Paradise 16

Qingshuan’s Programming Blog

Archive for July, 2008

Pirate game

Posted by linuxprogram on July 14, 2008

Sometimes you find a puzzle really messy, and you just put it aside. Next time when you pick it up, however, it magically becomes all clear.

Computing people all heard of the pirate game, and the following is some kind of the solution.

 

1, (100)                               1s

2, (0 ,100)                           1a,2s

3, (1 ,0 ,99 )                        1s,2a,3s

4, (0 ,1 ,0 , 99)                    1a,2s,3a,4s

5, (1 ,0 ,1 , 0, 98)                1s,2a,3s,4a,5s

………………………………

 

So for Nth, his solution would be:

 

  1. (N)p    := 100 – (n-1)/2     // himself
  2. (N-1)p  := 0               // next to him
  3. For i from 0 to N-2

          i := 1 – (i+1)

  4. End

Posted in Algo | Leave a Comment »