当前位置:网站首页>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(两个都可以,看你的程序如何编写)&#
边栏推荐
- Ruby tutorial
- RB technology stack
- Introduction to redis (1)
- Call Huawei order service to verify the purchase token interface and return connection reset
- 微信小程序:全新独立后台月老办事处一元交友盲盒
- 26.2 billion! These universities in Guangdong Province have received heavy support
- When the industrial Internet era is truly developed and improved, it will witness the birth of giants in every scene
- Apifox (postman + swagger + mock + JMeter), an artifact of full stack development and efficiency improvement
- A simple SSO unified login design
- 揭露测试外包公司,关于外包,你或许听到过这样的声音
猜你喜欢

POAP:NFT的采用入口?

Playwright之录制

微信小程序:最新wordpress黑金壁纸微信小程序 二开修复版源码下载支持流量主收益

Chia Tai International Futures: what is the master account and how to open it?

College degree, what about 33 year old Baoma? I still sell and test, and my monthly income is 13K+

每日刷题记录 (十三)

Detailed explanation of multi-mode input event distribution mechanism

Arbitrum:二维费用

【CTF】AWDP总结(Web)

Take you ten days to easily complete the go micro service series (IX. link tracking)
随机推荐
Yyds dry goods inventory kubernetes management business configuration methods? (08)
Postman automatically fills headers
107. SAP UI5 OverflowToolbar 容器控件以及 resize 事件处理的一些细节介绍
JS implementation determines whether the point is within the polygon range
Maximum number of "balloons"
Discrete mathematics: propositional symbolization of predicate logic
无心剑英译席慕容《无怨的青春》
Classification of performance tests (learning summary)
Global and Chinese market of veterinary thermometers 2022-2028: Research Report on technology, participants, trends, market size and share
【纯音听力测试】基于MATLAB的纯音听力测试系统
Expose testing outsourcing companies. You may have heard such a voice about outsourcing
如果消费互联网比喻成「湖泊」的话,产业互联网则是广阔的「海洋」
Inventory of more than 17 typical security incidents in January 2022
Daily question brushing record (13)
Talking about JVM 4: class loading mechanism
Query for Boolean field as "not true" (e.g. either false or non-existent)
The server time zone value ‘� й ��� ʱ 'is unrecognized or representatives more than one time zone【
当产业互联网时代真正发展完善之后,将会在每一个场景见证巨头的诞生
Database postragesql lock management
资深测试/开发程序员写下无bug?资历(枷锁)不要惧怕错误......