Array-11. Monkey Choice King (20) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Xu Jianchun (Zhejiang University)
A group of monkeys will choose the new Monkey King. The new Monkey King's choice is: Let n only the candidate monkeys in a circle, from a position from a sequence numbered 1-n. Starting from the 1th number, each round from 1 to report 3, where the report 3 of the monkeys are out of the circle, and then from the next close to a monkey start the same count. So constantly circulating, the last one left is chosen as the Monkey King. What is the original number of monkeys elected Monkey King?
Input format:
The input gives a positive integer n (<=1000) in a row.
Output format:
Prints the number of the selected monkey in a row.
Input Sample:
11
Sample output:
7
1#include <stdio.h>2#include <math.h>3#include <stdlib.h>4#include <string.h>5 intMain ()6 {7 intI, j =1, N, Count =0, a[1010];8Memset (A,0,sizeof(a));9scanf"%d", &n);Ten while(Count <N) One { A for(i =1; I <= N; i++) - { - if(!A[i]) the { - if(j%3==0) - { -A[i] =1; +count++; - if(Count = =N) + Break; A } atJ + +; - } - } - } -printf"%d\n", i); - return 0; in}
Array-11. The Monkey chose the king