当前位置:网站首页>约瑟夫问题
约瑟夫问题
2022-06-13 04:38:00 【算法与编程之美】
1 问题
已知 n 个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围。.从编号为 k 的人开始报数,数到 m 的那个人出圈;他的下一个人又从 1 开始报数,数到 m 的那个人又出圈;依此规律重复下去,直到剩余最后一个胜利者。. 例如:有10个人围成一圈进行此游戏,每个人编号为 1-10 。. 若规定数到 3 的人出圈。. 则游戏过程如下。(1)开始报数,第一个数到 3 的人为 3 号,3 号出圈。(2)从4号重新从1开始计数,则接下来数到3的人为6号,6号出圈。(3)按以上的方法依次类推。
2 方法

3 实验结果与讨论
通过实验、实践等证明提出的方法是有效的,是能够解决开头提出的问题。
代码清单 1
| ls = [I for I in range (1,42)] ls = [] num = 0 while len(ls1) > 1: num += 1 count = ls1.pop(0) if num == 3: ls2.append(count) num = 0 else: ls1.append(count) print(ls1) |
4 结语
本文介绍了约瑟夫环的问题来历,以及如何使用Python设计程序解决约瑟夫环,并且进行了拓展,使该程序能应用于更多相似的问题。但对于使用到函数的介绍相对空乏,并未通过举例详细介绍函数的使用方法,会对此加以改进。后续还会对Python算法的经典案例进行研究并以自己认为容易理解的方式进行分析,敬请期待!
边栏推荐
- Clear timer failure
- 2022 ICML | Pocket2Mol: Efficient Molecular Sampling Based on 3D Protein Pockets
- 如何优雅的处理async/await错误信息
- promise处理js多线程全部获得结果后同一处理结果
- 前几年的互联网人vs现在的互联网人
- The processing flow of thread pool depends on the core parameters
- How to implement a custom jdbc driver in only four steps?
- 推荐的图片临时在线压缩工具
- php开发16退出模块
- ES6 learning
猜你喜欢

Small program imitating Taobao Jiugong grid sliding effect

Collection of wrong questions in soft test -- morning questions in the first half of 2010
![C#获取WebService接口的所有可调用方法[WebMethod]](/img/44/4429b78c5b8341ed9a4a08d75a683e.png)
C#获取WebService接口的所有可调用方法[WebMethod]

【Flutter 问题系列第 67 篇】在 Flutter 中使用 Get 插件在 Dialog 弹窗中不能二次跳转路由问题的解决方案

记录一次排查问题的经过——视频通话无法接起

February 25, 2021 (Archaeology 12 year Landbridge provincial competition)

EMC rectification outline
![[flutter problem Series Chapter 67] the Solution to the problem of Routing cannot be jumped again in in dialog popup Using get plug - in in flutter](/img/59/0d95619ee3bba1f8992d90267d45c2.png)
[flutter problem Series Chapter 67] the Solution to the problem of Routing cannot be jumped again in in dialog popup Using get plug - in in flutter

一款開源的Markdown轉富文本編輯器的實現原理剖析

【Try to Hack】upload-labs通关(暂时写到12关)
随机推荐
PowerShell plus domain add computer module
PowerShell:因为在此系统上禁止运行脚本,解决方法
Idea Download
Ctfshow SQL injection (231-253)
Implementation of homepage header function in PHP development blog system
[flutter problem Series Chapter 67] the Solution to the problem of Routing cannot be jumped again in in dialog popup Using get plug - in in flutter
Solve the problem of running server nodemon reporting errors
How to use redis
Application of dagger2 learning module (II)
Catalan number
使用Service Worker优选请求资源 - 持续更新
Powershell 加域 Add-Computer模块
Tita performance treasure: remote one-on-one discussion
Redis data persistence
Redis主从复制、哨兵模式、集群
Ladder race
Crawler scrapy framework learning 2
【JS解决】leedcode 117. 填充每个节点的下一个右侧节点指针 II
Common terms of electromagnetic compatibility
E - Lucky Numbers