当前位置:网站首页>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(两个都可以,看你的程序如何编写)&#
边栏推荐
- 【CTF】AWDP总结(Web)
- Wechat applet: the latest WordPress black gold wallpaper wechat applet two open repair version source code download support traffic main revenue
- Package What is the function of JSON file? What do the inside ^ angle brackets and ~ tilde mean?
- “薪資倒掛”、“畢業生平替” 這些現象說明測試行業已經...
- Grabbing and sorting out external articles -- status bar [4]
- Single step debugging of master data reading of SAP commerce cloud products
- When the industrial Internet era is truly developed and improved, it will witness the birth of giants in every scene
- Intel sapphire rapids SP Zhiqiang es processor cache memory split exposure
- 微信小程序:最新wordpress黑金壁纸微信小程序 二开修复版源码下载支持流量主收益
- “薪资倒挂”、“毕业生平替” 这些现象说明测试行业已经...
猜你喜欢
潘多拉 IOT 开发板学习(RT-Thread)—— 实验4 蜂鸣器+马达实验【按键外部中断】(学习笔记)
Inventory of more than 17 typical security incidents in January 2022
小程序直播 + 电商,想做新零售电商就用它吧!
[development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39
ROS command line tool
Detailed explanation of multi-mode input event distribution mechanism
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)
“薪资倒挂”、“毕业生平替” 这些现象说明测试行业已经...
Nebula Importer 数据导入实践
随机推荐
Mongodb series learning notes tutorial summary
【CTF】AWDP总结(Web)
Playwright recording
Basic operation of database and table ----- the concept of index
Playwright之录制
pycharm专业版下载安装教程
【纯音听力测试】基于MATLAB的纯音听力测试系统
DOM basic syntax
107. Some details of SAP ui5 overflow toolbar container control and resize event processing
Database postragesql client connection default
【微处理器】基于FPGA的微处理器VHDL开发
Are you still writing the TS type code
Compare whether two lists are equal
[wave modeling 1] theoretical analysis and MATLAB simulation of wave modeling
142. Circular linked list II
小程序直播 + 电商,想做新零售电商就用它吧!
What is the current situation and Prospect of the software testing industry in 2022?
College degree, what about 33 year old Baoma? I still sell and test, and my monthly income is 13K+
那些一门心思研究自动化测试的人,最后都怎样了?
【大型电商项目开发】性能压测-优化-中间件对性能的影响-40