t*s 发帖数: 28 | 1 // Find the winner in the circle of N (nPlayers)
// players skipping M (nSkip) and removing Mth
// player. The winner is the last one left.
//
public int FindWinner(int a[]
int nPlayers,
int nSkip
)
其实就是那个什么joesph 问题。有什么好方法可以解?如果使用i=(i+1)%n 的方法,
complexity 不好。 | I*********g 发帖数: 93 | | t*s 发帖数: 28 | 3 google 到一个。不知道什么意思。
r := 0;
for i from 1 to n do
r := (r + k) mod i;
return r;
谁能给解释一下? | i***h 发帖数: 12655 | 4 hmm, thought of this,
but in later round, the skip may make of more than 1 round
of the original circle.
anyone can tell me if this is really the correct solution? I doubt it
【在 t*s 的大作中提到】 : google 到一个。不知道什么意思。 : r := 0; : for i from 1 to n do : r := (r + k) mod i; : return r; : 谁能给解释一下?
|
|