Time
limit:1000MS
Memory Limit:32768KB
64bit IO Format:%i64d &A mp %i64u Submit Status
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
2 2040
Sample Output
1 7 191 19 37 Program Analysis: This problem is more simple, read clearly test instructions on the line. Be sure to pay attention to the beginning of the Qing 0 work. There is a final input, and after the last digit there is no space, so a for statement is used. Program code:
#include <cstdio>#include<cstring>#include<iostream>using namespacestd;ints[5001];intMain () {intT; CIN>>T; while(t--) { inti,j,k,m; CIN>>m; memset (s),0,sizeof(s)); for(i=1; i<=m;i++) S[i]=i; K=2; while(m>3) { if(k==2){ for(j=1, i=1; i<=m;i++) { if(i%k==0) Continue; Elses[j++]=S[i]; } m=j-1; K=3; } Else{ for(j=1, i=1; i<=m;i++) { if(i%k==0) Continue; Elses[j++]=S[i]; } m=j-1; K=2; } } for(i=1; i<=m;i++) { if(i<m) cout<<s[i]<<" "; Elsecout<<s[i]<<Endl; } } return 0;}
C-linked list, recommended