"One" Problem description:
There are 17 people in a circle (numbered 0~16), starting from the No. 0 number of people from 1,
Those who report a multiple of 3 leave the circle and count until the last one is left.
Ask this person what is the original location?
"II" Problem solving:
1. Define the status of each number in the array record (whether it is eliminated);
2. If the number of persons who have not been eliminated is counted to 3, if the person is eliminated;
3. Continue this process until all are eliminated;
"Three" Sample code:
1 /*2 16. There are 17 people in a circle (numbered 0~16), starting from the No. 0 number of people from 1,3 Those who report a multiple of 3 leave the circle and count until the last one is left. 4 ask this person what is the original location? 5 */6 7 #define_crt_secure_no_warnings8#include <stdio.h>9#include <stdlib.h>Ten One voidMain () A { - intTotal = -, need = -, k =3; - intindex =0, Count =0, i =0; the inta[ -] = {0 }; - for (;;) - { -Index = index% total +1; + if(A[index] = =0) - { +i = (i +1) %K; A if(i = =0) at { -count++; -A[index] =1; - } - } - if(count = = need) Break; in } -printf"index =%d\n", index); toSystem"Pause"); +}
View Code
C language--n Individual in a circle to eliminate the problem