Huas Summer Training#2~c

Source: Internet
Author: User

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 20 40

Sample Output

1 7 19 1 19 37 Problem Solving Ideas:It should be noted that even if the number of soldiers is less than 3, but also to make a count, otherwise the problem can not be submitted. Note that each cycle is remembered to zero the number of statistics. Program code:#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace Std;
int a[5005];
int main ()
{
int n,i;
scanf ("%d", &n);
while (n--)
{
int m;
scanf ("%d", &m);
for (i=1;i<=m;i++)
A[i]=i;
int t=m;
while (T&GT;3)
{
int count=0;
for (i=1;i<=m;i++)
{
if (A[i])
count++;
if (count==2)
{
a[i]=0;
count=0;
t--;
}

} if (t<=3)
Break
count=0;
for (i=1;i<=m;i++)
{
if (A[i])
count++;
if (count==3)
{
a[i]=0;
count=0;
t--;
}

}if (t<=3)
Break


}
printf ("1");
for (i=1;i<=m;i++)
{
if (a[i]!=0)
{
if (i==1)
printf ("%d", a[i]);
Else
printf ("%d", a[i]);
}

}
cout<<endl;
}
return 0;
}

Huas Summer training#2~c

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.