当前位置:网站首页>PHP Joseph Ring problem

PHP Joseph Ring problem

2022-07-05 01:26:00 Know its black and accept its white

Origin of the problem

It is said that the famous Jewish historian Josephus Have the following story :

After the Romans took jotapat ,39 Jews and Josephus And his friends in a cave ,39 A Jew decided to die rather than be caught by the enemy , So I decided to commit suicide ,41 Individuals in a circle , From the first 1 Individual starts counting , Count to 3 You have to kill yourself , And then count again by the next , Until everyone killed himself .

However Josephus And his friends didn't want to comply .

Start with one person , Skip over k-2 personal ( Because the first one has been crossed ), And kill No k personal .
next , Over again k-1 personal , And kill No k personal .

The process goes all the way around the circle , Until there's only one left , This man can live on .

The problem is , Given and , Where to stand at first to avoid being executed .

Josephus Ask his friend to pretend to obey first , He arranged his friend and himself in the 16 And 31 A place , So I escaped the game of death .

Problem description

Joseph Ring problem is a very classic problem :
A circle has N personal (N For uncertain numbers ),
The number of the first person is 0 perhaps 1( Both can , See how your program is written )&#

原网站

版权声明
本文为[Know its black and accept its white]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050115001003.html