当前位置:网站首页>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(两个都可以,看你的程序如何编写)&#
边栏推荐
- Open3d uses GICP to register point clouds
- How to use words to describe breaking change in Spartacus UI of SAP e-commerce cloud
- Global and Chinese markets of emergency rescue vessels (errv) 2022-2028: Research Report on technology, participants, trends, market size and share
- Database postragesq peer authentication
- 揭露测试外包公司,关于外包,你或许听到过这样的声音
- 视频网站手绘
- 测试部新来了个00后卷王,上了年纪的我真的干不过了,已经...
- [microprocessor] VHDL development of microprocessor based on FPGA
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
- 【微处理器】基于FPGA的微处理器VHDL开发
猜你喜欢
Arbitrum:二维费用
pycharm专业版下载安装教程
各大主流编程语言性能PK,结果出乎意料
What happened to those who focused on automated testing?
Nebula Importer 数据导入实践
Redis master-slave replication cluster and recovery ideas for abnormal data loss # yyds dry goods inventory #
微信小程序:星宿UI V1.5 wordpress系统资讯资源博客下载小程序微信QQ双端源码支持wordpress二级分类 加载动画优化
Poap: the adoption entrance of NFT?
College degree, what about 33 year old Baoma? I still sell and test, and my monthly income is 13K+
Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!
随机推荐
RB technology stack
Four pits in reentrantlock!
SAP UI5 应用开发教程之一百零七 - SAP UI5 OverflowToolbar 容器控件介绍的试读版
[Chongqing Guangdong education] National Open University spring 2019 1042 international economic law reference questions
【大型电商项目开发】性能压测-优化-中间件对性能的影响-40
[development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39
微信小程序:微群人脉微信小程序源码下载全新社群系统优化版支持代理会员系统功能超高收益
C basic knowledge review (Part 3 of 4)
There is a new Post-00 exam king in the testing department. I really can't do it in my old age. I have
【CTF】AWDP总结(Web)
Inventory of more than 17 typical security incidents in January 2022
Intel sapphire rapids SP Zhiqiang es processor cache memory split exposure
Wechat applet: wechat applet source code download new community system optimized version support agent member system function super high income
[FPGA tutorial case 10] design and implementation of complex multiplier based on Verilog
Database postragesq peer authentication
Grabbing and sorting out external articles -- status bar [4]
26.2 billion! These universities in Guangdong Province have received heavy support
User login function: simple but difficult
Heartless sword English translation of Xi Murong's youth without complaint
SAP UI5 应用的主-从-从(Master-Detail-Detail)布局模式的实现步骤