当前位置:网站首页>PHP 约瑟夫环问题
PHP 约瑟夫环问题
2022-07-05 01:15:00 【知其黑、受其白】
问题来历
据说著名犹太历史学家Josephus有过以下的故事:
在罗马人占领乔塔帕特后,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,由第1个人开始报数,每报数到第3人该人就必须自杀,然后再由下一个重新报数,直到所有人都自杀身亡为止。
然而Josephus 和他的朋友并不想遵从。
首先从一个人开始,越过k-2个人(因为第一个人已经被越过),并杀掉第k个人。
接着,再越过k-1个人,并杀掉第k个人。
这个过程沿着圆圈一直进行,直到最终只剩下一个人留下,这个人就可以继续活着。
问题是,给定了和,一开始要站在什么地方才能避免被处决。
Josephus要他的朋友先假装遵从,他将朋友与自己安排在第16个与第31个位置,于是逃过了这场死亡游戏。
问题描述
约瑟夫环问题是一个很经典的问题:
一个圈共有N个人(N为不确定的数字),
第一个人的编号为0或者1(两个都可以,看你的程序如何编写)&#
边栏推荐
- Global and Chinese markets for industrial X-ray testing equipment 2022-2028: Research Report on technology, participants, trends, market size and share
- SAP ui5 application development tutorial 106 - how to improve the readability of SAP ui5 application routing URL trial version
- Heartless sword English translation of Xi Murong's youth without complaint
- 107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍
- dotnet-exec 0.6.0 released
- 揭露测试外包公司,关于外包,你或许听到过这样的声音
- Single step debugging of master data reading of SAP commerce cloud products
- Are you still writing the TS type code
- Inventory of more than 17 typical security incidents in January 2022
- Global and Chinese markets of radiation linear accelerators 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
“薪资倒挂”、“毕业生平替” 这些现象说明测试行业已经...
Arbitrum:二维费用
微信小程序:独立后台带分销功能月老办事处交友盲盒
The performance of major mainstream programming languages is PK, and the results are unexpected
Actual combat simulation │ JWT login authentication
What you learned in the eleventh week
整理混乱的头文件,我用include what you use
【大型电商项目开发】性能压测-优化-中间件对性能的影响-40
Basic operations of database and table ----- create index
Inventory of more than 17 typical security incidents in January 2022
随机推荐
Four pits in reentrantlock!
Playwright recording
Discrete mathematics: propositional symbolization of predicate logic
Talking about JVM 4: class loading mechanism
pycharm专业版下载安装教程
大专学历,33岁宝妈又怎样?我照样销售转测试,月入13k+
College degree, what about 33 year old Baoma? I still sell and test, and my monthly income is 13K+
[wave modeling 3] three dimensional random real wave modeling and wave generator modeling matlab simulation
The server time zone value ‘� й ��� ʱ 'is unrecognized or representatives more than one time zone【
视频网站手绘
[Yocto RM]11 - Features
The performance of major mainstream programming languages is PK, and the results are unexpected
LeetCode周赛 + AcWing周赛(T4/T3)分析对比
抓包整理外篇——————状态栏[ 四]
Database postragesq peer authentication
DOM basic syntax
[FPGA tutorial case 9] design and implementation of clock manager based on vivado core
Yyds dry goods inventory [Gan Di's one week summary: the most complete and detailed in the whole network]; detailed explanation of MySQL index data structure and index optimization; remember collectio
[FPGA tutorial case 10] design and implementation of complex multiplier based on Verilog
Take you ten days to easily complete the go micro service series (IX. link tracking)