It is said that the famous Jewish historian Josephus had the following story: After the Roman occupation of Chotapat, 39 Jews and Josephus and his friends hid in a hole, 39 Jews decided to prefer to die and not be caught, so decided to a suicide way, 41 people into a circle, By the 1th person starts to count, each count to the 3rd person The person must commit suicide, and then again by the next re-count, until everybody commits suicide to die. However, Josephus and his friends did not want to follow, Josephus to his friends to pretend to obey, he put friends and himself in the 16th and 31st position, so escaped the game of death. With the data structure of the loop list is relatively easy to implement, the following is the method I used to use the array (purely for playing a play) to complete the C program, should be implemented can also be improved.
1#include <stdio.h>2 3 intMain ()4 {5 intN = A;6 inti =1;7 intm =3;8 intMAX =N;9 intK, T;Ten inta[ -], b[ -]; One for(k =0; K < N; k++) A { -B[k] = k +1; - } the for(k =0; K < MAX; k++) - { -T = (i + M-1) %N; - if(T-1<0) + { -A[k] = b[n-1]; +i =N; A } at Else - { -A[k] = b[t-1]; -i =T; - while(T <N) - { inb[t-1] =B[t]; -t++; to } + } -n = n-1; theprintf"%i", A[k]); * } $printf"\ n");Panax Notoginseng return 0; -}
C/c++02:josephus problems