2016HUAS_ACM Summer Camp 1 A-soldier queue training problem

Source: Internet
Author: User

This problem I think is a simple simulation problem, tidy up the idea, make clear test instructions just fine.

Novice on the road, using two arrays for interactive assignment, the method is also relatively stupid, the idea is almost in the code comments.

Here are the main questions:

Start by numbering the soldiers starting from 1 (the total number of soldiers is not more than 5000), and then start 1 2 1 2 ... count off, check in 2 of the soldiers out, the remaining to the small ordinal direction, and then according to 1 2 3 1 2 3 ... Count off, Report 3 of the dequeue. And so on (1 2 1 2 ... and then 1 2 3 1 2 3 ... count off) until the remaining number of soldiers does not exceed 3 people, and output their original number.

The format requirements are as follows:The first line represents a test group N, and the next n rows are the number of soldiers per case. Sample Input22040 Sample OUTPUT1 7 191 19 37
1#include <iostream>2#include <string.h>3 using namespacestd;4 5 intn,n,i,j,a[5001],b[5001],c;//I generally prefer to define global variables .6 7 intMain ()8 {9CIN >>N;Ten      while(n--) One     { AMemset (A,0,sizeof(a));//initialize two arrays to be used -memset (b,0,sizeof(b)); -CIN >>N; the          for(i=1; i<=n;i++) -A[i]=i;//number of N recruits -          while(n>3)//execution of statements within a loop when the number is greater than 3 -         { +              for(i=1, j=1; i<=n;i++) -             { +                 if(i%2!=0)//1 2 1 2 ... a count of 2 of the full report, which is marked as even in the array of a, should be removed A                 { atB[j]=a[i];//Place the number of odd-numbered in the A array in the B-array -J + +; -                 } -             } -c=j-1;//J Executes a J + + after the last assignment, so the soldier left should be j-1 -             if(c<4)//If the condition is met, direct output, end this cycle in             { -                  for(i=1; i<c;i++) tocout<<b[i]<<' '; +cout<<b[c]<<Endl; -                  Break; the             } *              for(j=1, i=1; j<=c;j++)//1 2 3 1 2 3 ... $             {Panax Notoginseng                 if(j%3!=0) -                 { theA[I]=B[J];//put the number of multiples of 3 in the B array in the A array +i++; A                 } the             } +n=i-1;//with the above c=j-1; -         } $         if(n<4) $         { -              for(i=1; i<n;i++) -cout<<a[i]<<' '; thecout<<a[n]<<Endl; -         }Wuyi     } the     return 0; -}
View Code

2016HUAS_ACM Summer Camp 1 A-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.