当前位置:网站首页>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 market of veterinary thermometers 2022-2028: Research Report on technology, participants, trends, market size and share
- The server time zone value ‘� й ��� ʱ 'is unrecognized or representatives more than one time zone【
- [flutter topic] 64 illustration basic textfield text input box (I) # yyds dry goods inventory #
- 【微处理器】基于FPGA的微处理器VHDL开发
- Database postragesql lock management
- Intel sapphire rapids SP Zhiqiang es processor cache memory split exposure
- Complex, complicated and numerous: illustration of seven types of code coupling
- How to use words to describe breaking change in Spartacus UI of SAP e-commerce cloud
- 揭露测试外包公司,关于外包,你或许听到过这样的声音
- DOM basic syntax
猜你喜欢

Arbitrum: two-dimensional cost

What happened to those who focused on automated testing?

JS implementation determines whether the point is within the polygon range

微信小程序:全新独立后台月老办事处一元交友盲盒

Behind the cluster listing, to what extent is the Chinese restaurant chain "rolled"?
![[untitled]](/img/d1/85550f58ce47e3609abe838b58c79e.jpg)
[untitled]

大专学历,33岁宝妈又怎样?我照样销售转测试,月入13k+

Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!

Playwright之录制

Remote control service
随机推荐
Behind the cluster listing, to what extent is the Chinese restaurant chain "rolled"?
Wechat applet: exclusive applet version of the whole network, independent wechat community contacts
BGP comprehensive experiment
潘多拉 IOT 开发板学习(RT-Thread)—— 实验4 蜂鸣器+马达实验【按键外部中断】(学习笔记)
142. Circular linked list II
Database postragesql client authentication
[FPGA tutorial case 10] design and implementation of complex multiplier based on Verilog
Global and Chinese markets for industrial X-ray testing equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Implementation steps of master detail detail layout mode of SAP ui5 application
There is a new Post-00 exam king in the testing department. I really can't do it in my old age. I have
"Upside down salary", "equal replacement of graduates" these phenomena show that the testing industry has
[Chongqing Guangdong education] National Open University spring 2019 1042 international economic law reference questions
Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!
揭露测试外包公司,关于外包,你或许听到过这样的声音
SAP UI5 应用开发教程之一百零六 - 如何提高 SAP UI5 应用路由 url 的可读性试读版
Call Huawei order service to verify the purchase token interface and return connection reset
Global and Chinese market of portable CNC cutting machines 2022-2028: Research Report on technology, participants, trends, market size and share
“薪資倒掛”、“畢業生平替” 這些現象說明測試行業已經...
Global and Chinese markets for stratospheric UAV payloads 2022-2028: Research Report on technology, participants, trends, market size and share
What is the current situation and Prospect of the software testing industry in 2022?