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
Sample Output
1 7 191 19 37 test Instructions: N soldiers in the order of 1~n, first from the left to the right, a number of alternating, the report 2 out of the team, and then from left to right in alternating count, reporting 3 out of the team, the cycle of the two processes, until the queue of <=3 so far. Finally output the original number of the remainder. Idea: Direct simulation of the two processes, until the number of <=3, the final output results. Code:#include <cstdio>int a[5001];//using namespace Std;int main () {int n,x,b,c; scanf ("%d", &n); while (n--) {scanf ("%d", &x); B=x; for (int i=1;i<=x;i++) a[i]=i; while (b>3) {c=0; for (int i=1;i<=x;i++) {if (a[i]==0) continue; else c+=1; if (c==2) {a[i]=0; c=0; }} B=B-B/2; if (b<=3) break; c=0; for (int i=1;i<=x;i++) {if (a[i]==0) continue; else c+=1; if (c==3) {a[i]=0; c=0; }} B=B-B/3; } c=0; for (int i=1;i<=x;i++) {if (a[i]==0) continue; else {C+=1; if (c==b) printf ("%d\n", A[i]); else printf ("%d", a[i]); }}} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1276 Soldier Queue Training problem