Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ / Visual Studio The Josephus problem is a well-known game, stated as follows N people, numbered 1 to N, are sitting in a circle.

C++ / Visual Studio

image text in transcribed

The Josephus problem is a well-known game, stated as follows N people, numbered 1 to N, are sitting in a circle. Starting at person 1, a hot potato is passed from one person to the next. After M passes, the person holding the hot potato is eliminated, and the circle closes ranks. The person who was sitting after the eliminated person picks up the hot potato, and the game continues. The last remaining person wins Thus, for example, if M = 0 and N = 5, players are eliminated in order, and player 5 wins. IfM 1 and N-5, the order of elimination is 2, 4, 1, 5. Write a program to solve the Josephus problem for general values of M and N. That is, it should prompt the user for M and N values, then print the sequence of elimination (as per the above examples), and the winner. You should use a list (from STL) to store the persons, and make your program as efficient as possible

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago