Title: N Numbers (0,1,..., n-1) Form a circle, starting with the number 0, each time the number of m digits is removed from the circle (the first
Is the current number itself, and the second is the next digit of the current number). When a number is deleted, the next move from the deleted number continues to delete
The number of the first M. Find the last number left in this circle
Idea: This is the Joseph ring problem, using the list in the STL to solve, is the most basic solution
int Joseph (list<int>& ring,int k) {list<int>::iterator ITR = Ring.begin (), Temp;int M;while (Ring.size () >1) {m =1;if (ITR = = Ring.end ()) ITR = Ring.begin (); while (M <k) {if (ITR = Ring.end ()) ITR =ring.begin (); Itr++;m++;if ( ITR = = Ring.end ()) ITR =ring.begin ();} temp = itr;itr++;ring.erase (temp);} ITR = Ring.begin (); return *itr;}
Joseph Ring Question