The Josephus Problem
2007-05-24 13:25
176 查看
The Josephus Problem
We suppose that J(n) is the surviving people's index.
Let’s suppose that we have 2n people originally. After the first go-round, we’re left with
That is,
J(2n) = 2J(n) - 1 , for n ≥ 1 .
Considering 2n+1 people originally,
Thus,
J(2n+1) = 2J(n) + 1 , for n ≥ 1 .
Summarize the passage above , we can get.
J(1) = 1;
J(2n) = 2J(n) - 1 , for n ≥ 1 ; (1)
J(2n+1) = 2J(n) + 1 , for n ≥ 1 .
Our recurrence (1) makes it possible to build a table of small values quickly.
Figure 1
With figure 1,we guess that (Donald E. Knuth prove that it is true)
J(2 m + i) = 2i + 1, for m ≥ 0 and 0 ≤ i < 2 m.
Suppose n’s binary expansion is
n = (bm b m-1 b m-2 …b 1 b 0) 2; bm = 1;
Then
i = (0 b m-1 b m-2 …b 1 b 0) 2;
J(n) = (b m-1 b m-2 …b 1 b 0 bm) 2;
Now we can get J(n) from n by doing a one-bit cyclic shift left! ^_^ Nice~~
What is “ fixed point ” ?
If J(n) = n, then we call J(n) is fixed point .
J(13) = J((1101) 2) = (1011) 2
J((1011) 2)= (0111) 2 = (111) 2
J(J(13)) = J((1011) 2) =(111) 2
J(…J(13)) = J((1011) 2) =(111) 2
Leon
2007-5-22
We suppose that J(n) is the surviving people's index.
Let’s suppose that we have 2n people originally. After the first go-round, we’re left with
1 |
3 |
5 |
2n-1 |
2n-3 |
… |
↑ |
2 |
3 |
2n |
2n-1 |
… |
↑ |
→ |
1 |
3 |
5 |
2n-1 |
2n-3 |
… |
↑ |
2 |
3 |
2n |
2n-1 |
… |
↑ |
→ |
1 |
J(2n) = 2J(n) - 1 , for n ≥ 1 .
Considering 2n+1 people originally,
1 |
5 |
7 |
2n+3 |
2n-1 |
… |
↑ |
2 |
3 |
2n |
2n-1 |
… |
↑ |
→ |
3 |
J(2n+1) = 2J(n) + 1 , for n ≥ 1 .
Summarize the passage above , we can get.
J(1) = 1;
J(2n) = 2J(n) - 1 , for n ≥ 1 ; (1)
J(2n+1) = 2J(n) + 1 , for n ≥ 1 .
Our recurrence (1) makes it possible to build a table of small values quickly.
Figure 1
n | 1 | 2 3 | 4 5 6 7 | 8 9 10 11 12 13 14 15 | 16 |
J(n) | 1 | 1 3 | 1 3 5 7 | 1 3 5 7 9 11 13 15 | 1 |
With figure 1,we guess that (Donald E. Knuth prove that it is true)
J(2 m + i) = 2i + 1, for m ≥ 0 and 0 ≤ i < 2 m.
Suppose n’s binary expansion is
n = (bm b m-1 b m-2 …b 1 b 0) 2; bm = 1;
Then
i = (0 b m-1 b m-2 …b 1 b 0) 2;
J(n) = (b m-1 b m-2 …b 1 b 0 bm) 2;
Now we can get J(n) from n by doing a one-bit cyclic shift left! ^_^ Nice~~
What is “ fixed point ” ?
If J(n) = n, then we call J(n) is fixed point .
J(13) = J((1101) 2) = (1011) 2
J((1011) 2)= (0111) 2 = (111) 2
J(J(13)) = J((1011) 2) =(111) 2
J(…J(13)) = J((1011) 2) =(111) 2
Leon
2007-5-22
相关文章推荐
- 约瑟夫问题 The Josephus Problem 非递归算法求解
- The Josephus Problem
- UVa 10025 The ? 1 ? 2 ? ... ? n = k problem
- [UVA10245] The Closest Pair Problem && 暴力版本
- hit 1001 a+b problem (the same as hdu,poj)
- The Secret to 10 Million Concurrent Connections -The Kernel is the Problem, Not the Solution
- 湘潭市赛 Josephus Problem 线段树
- hdoj2058 The sum problem
- HDOJ 5373 The shortest problem 【数论】
- Solving the Last Item Problem for a Circular Distribution with Partially Overlapping Items
- 【Jason's_ACM_解题报告】The Blocks Problem
- The 6th Zhejiang Provincial Collegiate Programming Contest->ProblemK:K-Nice
- 2014 Asia Xian Regional Contest G The Problem to Slow Down You 【Palindromic Tree】
- The Blocks Problem
- 已解决“pkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem”
- poj 3590 The shuffle Problem
- 杭电OJ——1032 The 3n + 1 problem
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Pokemon Master
- 【ACM菜逼解题报告】The Blocks Problem
- 101 - The Blocks Problem