您的位置:首页 > 产品设计 > UI/UE

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
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

That is,

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

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

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

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  build table