The Josephus Problem

本文探讨了约瑟夫环问题中的数学规律,通过递推公式解析了不同人数时幸存者的编号,并给出了求解该问题的一个巧妙方法:对输入进行位移运算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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-2b 1 b 0) 2;   bm = 1;

Then

i = (0 b m-1 b m-2b 1 b 0) 2;

J(n) = (b m-1 b m-2b 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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值