有 5 名成员围坐在一张桌子旁。关键值是坐在桌子周围的成员数量。所以现在关键值为5。一名恐怖分子告诉成员,由于你们有5名成员,我将从第一个成员开始数起,数到5的人将被枪杀。
他数了数,第五个人死了。他再次数到五,第一个人死了。他再次数数,第三个人死了,现在还剩下2和4。他数着他们之间的数,最后4将被算作5,他被枪杀。最后剩下的人将是2。
如果尝试的话也是一样的对于七个人来说,答案是 8。
对于 8 个人来说,答案是 4。
如何为此设置一个公式,以便计算机能够正确拍摄该人。
我猜想它可能是在一个循环链表中,通过给成员提供一个令牌值。但我无法得出一个等式。因此,通过给出关键值,将确定将生存的人。
There are 5 members sitting around a table. Key value is the number of members sitting around the table. So now the key value will be 5. A terrorist told the members that as you are 5 members I will count from first member and the person who is counted 5 will be shot dead.
He counts and the 5th person dies. Once again he counts up to five and the 1st person dies. Once again he counts and the 3rd person dies, and now 2 and 4 are remaining.He counts the no between them finally 4 will be counted as 5 and he is shot dead.The last person remaining will be 2.
Like the same if tried for seven persons the answer will be 8.
And for 8 persons the answer will be 4.
How to set a formula for this so that computer can shoot the person correctly.
I guess it might be in a circular linked list by giving a token value to the members.But i could not arrive at an equation. So by giving the key value the person who will live will be determined.
发布评论
评论(3)
这是一个名为约瑟夫问题的经典问题。
它有递归解:
J (1) = 1 ;这是基础
当 n 为偶数时 J(2n) = 2J(n) - 1
当 n 为奇数时 J(2n + 1) = 2J(n) + 1
it's classic problem named Josephus problem .
it has recursive solution :
J (1) = 1 ; this is the basis
when n is even J(2n) = 2J(n) - 1
when n is odd J(2n + 1) = 2J(n) + 1
这被称为约瑟夫问题。
This is termed the Josephus problem.
这是一个众所周知的问题,称为约瑟夫问题。检查 wikipedia 和 mathworld 寻找可能的解决方案。您可以使用 Google 查找大量有关它的文章。
This is a well known problem called Josephus problem. Check wikipedia and mathworld for possible solution. And you can use Google for numerous articles on it.