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