HDU 1279 Soldier Queue Training problem

Source: Internet
Author: User

Soldier Queue Training Problem

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4602 Accepted Submission (s): 2145


problem Descriptiona 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.
 
InputThere are multiple test data sets, number of first action Group N, followed by n rows of recruits, the number of recruits not exceeding 5000.
 
Outputtotal 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
22040
 
Sample Output
1 7 191) 19 37
 
AuthorCai Minglun 
SourceHangzhou Electric ACM Training Team Training Competition (VI) Ideas:The main problem is to let through the loop, will be divisible by 2 number of discarded, and then in accordance with the order of the existing re-assignment, and then the number can be divisible by 3 to discard, and then re-assign the value in the order, and after the exclusion of several to see the existing number enough three, if greater than 3, continue to loop, or To output, but remember at the beginning of the time also to determine whether greater than 3, if greater than 3, and then into the loop, or direct output! The specific code is as follows:
This problem in the exam when I was a long time, is because not to n>3 and <=3 to separate consideration, if less than equal to three of the words//do not have to be counted out, the direct output on the line! This point you can solve with the method of trial number, which reflects the//importance of the trial number! #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <    Algorithm>using namespace Std;int a[5005],b[5005];int main () {int t,n,m,i,j,k,t,d[5];scanf ("%d", &t); while (t--) {scanf ("%d", &n),//n=t;for (i=1;i<=n;i++)//This is used to store the number of soldiers in the queue (new number will be new) {a[i]=i; b[i]=1;// Array B is used for if in the queue, then one means that if the dequeue, then the}t=n;//is used to indicate that the n will change in the calculation, so to re-assign the value, replace it with another variable change! if (n>3)//When n>3, because the need to dequeue, so according to test instructions execution can, remember, after executing for (j=1;j<=n;j++)//Soldier's order does not change, but the serial number has changed! , so in each of them to re-i=1,k=0;i<=n;i++ {for ()//To the soldier assignment operation! But finally the original number needs to be output! {if (A[i]%2==0&&b[i])//This is not difficult because the subscript of the tag array you have not changed, so then {b[i]=0;//the array b corresponds to the 1 element of the subscript output to the line! t--;}       else if (B[i]) {k++;a[i]=k;} }if (t<=3) break;for (i=1,k=0;i<=n;i++) {if (A[i]%3==0&&b[i]) {b[i]=0;t--;} else if (B[i]) {k++;a[i]=k;}}   if (t<=3) break;} for (i=1,j=0;i<=n;i++)//Because the formatting requirements on the topic are relatively strict, so weTo make an assignment to an array, make the output of {if (B[i])//comparison specification!   D[j++]=i;   } if (t==3) printf ("%d%d%d\n", d[0],d[1],d[2]);   else if (t==2) printf ("%d%d\n", d[0],d[1]); else if (t==1) printf ("%d\n", D[0]);} return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 1279 Soldier Queue Training problem

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.