At first glance, this question is very similar to utherv's problem. The difference is that each time it starts from 1. The solution is similar. Recursive Formula for mathematical solutions.
It is assumed that after the k-th report, the remaining number of people cannot exceed 3.
If the first K times is a 1-3 Report, the number of the current index n of the three numbers can be pushed to N + (n-1)/2 before the Previous Report, which is easy to understand, because every three people need to remove the third person, (n-1)/2 can know that a few people have been removed, plus the basic number n is the number of the last report;
If the K number is 1-2, this is very simple. The number of the current index n is 2n-1 in the previous report.
Therefore, the county calculates the number of reports and returns the initial values of the remaining numbers in reverse order.
1 #include <cstdio> 2 #include <cstring> 3 4 int main() { 5 int t, n, m; 6 int i, j; 7 int a[4]; 8 9 scanf("%d", &t);10 while (t--) {11 scanf("%d", &n);12 m = 0;13 while (n > 3) {14 ++m;15 if (m & 1)16 n -= n/2;17 else18 n -= n/3;19 }20 for (i=1; i<=n; ++i)21 a[i] = i;22 while (m > 0) {23 if (m & 1) {24 for (i=1; i<=n; ++i)25 a[i] = 2*a[i]-1;26 } else {27 for (i=1; i<=n; ++i)28 a[i] = a[i]+(a[i]-1)/2;29 }30 --m;31 }32 printf("%d", a[1]);33 for (i=2; i<=n; ++i)34 printf(" %d", a[i]);35 printf("\n");36 }37 38 return 0;39 }
[Hdoj] 1276 soldiers queue Training Problems