2016CVTE programming Problem: Rabbit hide Hole

Source: Internet
Author: User

Rabbit Hide HoleTitle Descriptiona rabbit hiding in 20 round arranged holes (hole numbering from 1), a wolf from the X hole to find, next time a hole to find (and in x+2 hole), in the next two holes to find (and in x+5 hole), and so on ... It was found N times still not found. Ask the rabbit maybe in those holes.

Input Description:
Enter more than one set of data, with two integers per row of x and N (x <= 20,n <= 100000)
Output Description:
Each group of data is output from small to large in the order of the rabbit may be in the hole, separated by a space between the numbers. If every hole refuses to hide the rabbit, output-1.
Solving

Direct violence, the detected position can not have the rabbit, the remaining position is the possible location
The sequence of Detection holes is: 0 2 5 9, the array is an = An-1 + N
At the same time the round of the hole, to 20 to find the remainder, when the 0 is the 20th hole.
 ImportJava.util.Scanner; Public classmain{ Public Static voidmain (String [] args) {Scanner in=NewScanner (system.in); //arraylist<integer> list = new arraylist<integer> ();        int[] A; intX,n; intA1=0,a2=0; intId=0; BooleanFlag =true;  while(In.hasnext ()) {x=In.nextint (); N=In.nextint (); A=New int[21];  for(inti = 1;i<= n;i++){                if(i = = 1) {A1= 0; ID= (A1 +x); }Else{A2= A1 +i; A1=A2; ID= (A2 +x); }                 if(id% 20 ==0)//0 converted to number 20thid = 20; ElseID= Id%20; A[id]=-1; }             for(inti = 1;i<= 20;i++){                if(A[i] ==0) {flag=false; System.out.print (i+" "); }            }            if(flag) System.out.println (-1); ElseSystem.out.println (); }    }}

2016CVTE programming Problem: Rabbit hide Hole

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.