码迷,mamicode.com
首页 > 其他好文 > 详细

The Josephus problem

时间:2014-10-19 11:21:09      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:http   io   os   ar   for   sp   on   art   cti   

Legend has it that Josephus wouldn‘t have lived to become famous without his mathematical talents. During the Jewish-Roman war, he was among a band of 41 Jerish rebels trapped in a cave by Romans. Preferring suicide to capture, the rebels decide to form a circle, and proceeding around it, to kill every third remaining person until no one was left. But Josephus, among with an unindicted co-conspirator, wanted none of this suicide nonsense; so he quickly calculated where he and his friend should stand in the vicious circle.

In our variation, we start with  bubuko.com,布布扣 people numbered 1 to bubuko.com,布布扣 around a circle, and we eliminate every bubuko.com,布布扣 remaining person until ONLY one survives. For example, here‘s the starting configuration for bubuko.com,布布扣=10.

The elimination order is 2, 4, 6, 8, 10, 3, 7, 1, 9, so 5 survives. The problem: determine the survivor‘s number bubuko.com,布布扣.

Suppose that we have bubuko.com,布布扣 people originally. After the first goround, we are left with 1, 3, 5, 7, ... , bubuko.com,布布扣. and 3 will be the next to go. this is just like starting out with bubuko.com,布布扣 people, except that each person‘s number has been doubled and decreased by 1. That is,

bubuko.com,布布扣

But what about the odd case? with bubuko.com,布布扣 people, it turns out that person number 1 is wiped out just after person number bubuko.com,布布扣, and we are left with 3, 5, 7, 9, ..., bubuko.com,布布扣

Again we almost have teach original situation with bubuko.com,布布扣 people, But this time their number is doublede and increased by 1. Thus 

bubuko.com,布布扣

Noticing that bubuko.com,布布扣.

Now we seek a closed form, because that will be even quicker and more informative. After all, that is a matter of life or death.

Our recurrence makes it possible to build a table of small values very quickly. Perhaps we‘ll be able to splot a pattern and guess the answer.

1

2

3

4

5

6

7

8

1

1

3

1

3

5

7

1

It seems we can group by power of 2. bubuko.com,布布扣 is always 1 at the beginning of group and it increases by 2 within a group. So if we write bubuko.com,布布扣 in the form bubuko.com,布布扣, where bubuko.com,布布扣 is the largest power of 2 not exceeding bubuko.com,布布扣 and where bubuko.com,布布扣 is what‘s left, the solution to our recurrence seems to be

bubuko.com,布布扣

We must now prove this function.The induction step has two parts, depending on whether bubuko.com,布布扣 is odd or even. If bubuko.com,布布扣 and bubuko.com,布布扣, then bubuko.com,布布扣 is even and

bubuko.com,布布扣

A similar proof works in the odd case, when bubuko.com,布布扣. We might also note that bubuko.com,布布扣.

The Josephus problem

标签:http   io   os   ar   for   sp   on   art   cti   

原文地址:http://www.cnblogs.com/taokongcn/p/4034352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!