Question: The problem is known as the Josephus problem and postulates a group of people of size N are standing in a circle waiting to be
The problem is known as the Josephus problem and postulates a group of people of size N are standing in a circle waiting to be eliminated. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of M people are skipped, the next person is eliminated. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains. For example, suppose that M = 3 and there are N = 5 people named A, B, C, D and E. We count three people starting at A, so that C is eliminated first. We then begin at D and count D, E and back to A, so that A is eliminated next. Then we count B, D and E, and finally B, D and B, so that D is the one who remains last. For this computer assignment, you are to write and implement a C++ program to simulate and solve the Josephus problem. The input to the program is the number M and a list of N names, which is clockwise ordering of the circle, beginning with the person from whom the count is to start. After each removal, the program should print the names of all people in the circle until only one person remains. However, to save the printing space, print the names of the remaining people only after K elimination, where K 2 1 is also an input argument to the program. The input arguments N, M and K can be entered from the stdin in the given order 1. Name the people in the circle in the following sequence: A1, A2 A9, B1, B2 N and M when the program prompts for them and use a list
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
