Test instructions
Description
A troop of recruits queue training, the recruits from the beginning in order sequentially numbered, side-by-line ranks, the training rules are as follows: From the beginning of a two count, where the two check out, the remaining to the small ordinal direction, and then from the beginning of a three count, where reporting three of the row, the remaining to the small ordinal direction, Continue from scratch to two count off ... , from beginning to end in rotation from one to two, one to three count off until the remaining number of not more than three people.
Input
There are multiple test data sets, number of first action Group N, followed by n rows of recruits, the number of recruits not exceeding 5000.
Output
Total n rows, corresponding to the number of recruits entered, each line outputs the original number of the remaining recruits, with a space between the numbers.
Sample Input
22040
Sample Output
1 7 191 19 37 Train of thought: The Soldier 1-2 Counts, uses the circulation formula I% 2 + 1 = 2 to find out the soldiers who report 2, to make their numbers larger, to calculate the remainder, from the big to the small, the soldiers 1-3 count off. The last three people left are just the first three digits of the output array. Source:
1#include <iostream>2#include <algorithm>3 using namespacestd;4 #defineMAXN 50005 intMain ()6 {7 intT;8CIN >>T;9 while(t--)Ten { One intCount=0; A intA[maxn],num; -CIN >>num; - intNUM1 =num; the for(inti =0; i < num; i++) - { -a[i]=i+1; - } + while(num>3) - { + for(inti =0; i < num; i++) A { at ifI2+1==2) - { -A[i] =num1+1;//the number of the soldiers, numbered 2, becomes larger. -count++; - } - in } -Sort (A, a + num);//Reorder , leaving the rest of the soldiers in front. tonum= num-num/2;//Calculate the rest of the people + - if(num<=3) the { * Break; $ }Panax Notoginseng Else - { the for(inti =0; i < num; i++) + { A if(i%3+1==3) the { +A[i] = num1+1;//make the number bigger so that the back sort is in the back. - } $ $ } -Sort (A, A +num); -num = num-num/3; the - }Wuyi } the for(inti =0; I < num-1; i++) - { Wucout << A[i] <<" ";//output The last three people - } Aboutcout << A[num-1] <<Endl; $ } - - return 0; -}
Experience:
Feel Good ... Come on!
Recruit Training ([email protected][email protected]=)