Topic:
Soldier Queue Training Problem |
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) |
Total submission (s): Accepted submission (s): 37 |
|
Problem description A troop to carry out the Recruit queue training, the recruits from the beginning in order sequentially numbered, row by line ranks, the rules of training are as follows: From the beginning to two count, where the two check out, the remaining to the small ordinal direction, and then from the beginning of one to three off, Where report three of the row, the rest of the direction of the small number, continue to start from the beginning of one 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 has a number of test data sets, number of first action Group N, followed by n rows of recruits, the number of recruits not more than 5000.
|
Output has 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 Input22040 |
Sample Output1 7 191) 19 37 |
Authorcai Minglun |
SOURCE Hangzhou Electric ACM Training Team Training Tournament (VI) |
Recommendlcy |
Topic Analysis:
Simple simulation. This question may be a little puzzled by how the input sample gets the output sample. Here are some of your own understandings:
The code is as follows:
/* * f.cpp * * Created on:2015 March 19 * author:administrator * * #include <iostream> #include <cstdio>usin G namespace Std;const int maxn = 5001;int Soldier[maxn];int main () {int t;scanf ("%d", &t), while (t--) {int n;scanf ("%d ", &n); int i;for (i = 1; I <= N; ++i) {Soldier[i] = i;} int cnt = 0;int sum = n;if (sum <= 3) {int J;int flag = 1;for (j = 1; j <= N; ++j) {if (flag = = 1) {flag++;p rintf ("% D ", Soldier[j]);} else {printf ("%d", Soldier[j]);}} printf ("\ n"); continue;} while (true) {/////When the number of people in the team is >3, the int j;for (j = 1; j <= N; ++j) {////two minus one if (soldier[j]! = 0) {cnt++;if (cnt = =) for the first time 2) {cnt = 0;soldier[j] = 0;sum--;}}} If after each of the two removed one, the number of the team has <=3if (sum <= 3) {break;//jump out of the loop}//can execute the following code to prove that the number of troops has not <=3cnt = 0;//will be in the counter of the clear 0for (j = 1; J & lt;= N; ++J) {//second time every 3 minus one if (soldier[j]! = 0) {cnt++;if (cnt = = 3) {cnt = 0;soldier[j] = 0;sum--;}}} if (sum <= 3) {///If the number of people in the team has <=3break;//after each of the 3 removed one, then it jumps out of the loop}//if you can execute the following code, then there is no <=3cnt = 0;//to clear the counter 0}// Put the last remainingThe person outputs the INT flag = 1;for (i = 1; I <= n; ++i) {/** * Note the processing of the data output format. * Output format to strictly follow the form of x_x_x_x (_ denotes a space) * Do not output to x_x_x_x_, this will be P E */if (soldier[i]! = 0) {if (flag = = 1) {//The first data does not require an output space, that is, the output "X" in the form of data can be flag++;p rintf ("%d", Soldier[i]);} else {//If it is not the first Data p rintf ("%d", soldier[i]);//Output "_x" in the form of data}}}printf ("\ n");} return 0;}
(Hdu step 8.1.6) Soldier Queue Training problem (data structure, simple simulation-the first time every 2 removed 1, the second time every 3 removed 1.) know the number of people in the team <=3, output the remainder)