首页

欢迎

 

Welcome

欢迎来到这里, 这是一个学习数学、讨论数学的网站.

转到问题

请输入问题号, 例如: 2512

IMAGINE, THINK, and DO
How to be a scientist, mathematician and an engineer, all in one?
--- S. Muthu Muthukrishnan

Local Notes

Local Notes 是一款 Windows 下的笔记系统.

Local Notes 下载

Sowya

Sowya 是一款运行于 Windows 下的计算软件.

详情

下载 Sowya.7z (包含最新版的 Sowya.exe and SowyaApp.exe)


注: 自 v0.550 开始, Calculator 更名为 Sowya. [Sowya] 是吴语中数学的发音, 可在 cn.bing.com/translator 中输入 Sowya, 听其英语发音或法语发音.





注册

欢迎注册, 您的参与将会促进数学交流. 注册

在注册之前, 或许您想先试用一下. 测试帐号: usertest 密码: usertest. 请不要更改密码.


我制作的 slides

Problem

随机显示问题

Problèmes d'affichage aléatoires

计算数学 >> 数据结构
Questions in category: 数据结构 (Data Structure).

Josephus 问题

Posted by haifeng on 2018-04-10 13:08:04 last update 2018-04-10 15:14:26 | Answers (0)


Josephus 问题是指下面的游戏:

 

有 $N$ 个人坐成一圈, 编号依次为 $1,2,3,\ldots,N$.

从编号 $1$ 的人开始传递马铃薯. $M$ 次传递之后, 持有热马铃薯的人退出游戏, 圈缩小. 然后游戏从退出者下一位开始, 继续进行.

最终留下来的人获胜.

这样, 如果 $M=0$ 并且 $N=5$, 那么参加游戏的人依次退出, $5$ 号获胜.

如果 $M=1$ 并且 $N=5$, 那么退出的顺序就是 $2$、$4$、$1$、$5$. 最后是 $3$ 号获胜.

 


比如:

Josephus problem!
Please input the number of players: N = 5

Please input the gap: M = 1
N=5
M=1
start index =1
deleting 2
now vector a is
1 3 4 5
next index =2
--------------
start index =2
deleting 4
now vector a is
1 3 5
next index =3
--------------
start index =3
deleting 1
now vector a is
3 5
next index =1
--------------
start index =1
deleting 5
now vector a is
3
next index =2
--------------
start index =2
deleting 3
now vector a is
next index =1
--------------
=======================
The queue is:
2 4 1 5 3

 

 


References:

《数据结构与算法分析C++描述》(第3版)P.81, Exer 3.6.

https://en.wikipedia.org/wiki/Josephus_problem