Home > Back-end >  Sum don't understand, ask the great spirit.
Sum don't understand, ask the great spirit.

Time:10-01

45 kindergarten in a circle, 1 count off, clockwise from the monitor to report out 3, the next starting from 1, back and forth so that number off, after the last the rest of the monitor is clockwise side which one of the class?
Pray tell, completely don't understand,

CodePudding user response:

Where is the great god?

CodePudding user response:

Come on answer!

CodePudding user response:

First cycle monitor stand out on the right side of the 3rd, can be divided exactly by 3 of the time monitor the beginning
Monitor of the second loop is on the right side of the original monitor on the right side of the fourth personal is also the last time the cycle start at 1
Monitor of the third loop is on the right side of the original queue monitor on the right side of fifth man, is also the second cycle start at 1
By analogy, the elder brothers can only help you to this, the rest of the cycle counting on you to use a while loop

CodePudding user response:

reference qq_34031663 reply: 3/f
first cycle monitor stand out on the right side of the 3rd, can be divided exactly by 3 of the time monitor the beginning
Monitor of the second loop is on the right side of the original monitor on the right side of the fourth personal is also the last time the cycle start at 1
Monitor of the third loop is on the right side of the original queue monitor on the right side of fifth man, is also the second cycle start at 1
By analogy, the elder brothers can only help you to this, the rest of the cycle counting on you to use a while loop


Truth to understand, is to write bad code,,,,

CodePudding user response:

The problem can be solved with a linked list and Joseph is similar

CodePudding user response:

 import Java. Util. LinkedList; 
Import the Java. Util. List;
/* *
* M people, the number 1 - M, respectively, the M men sequentially arranged in a circle,
* now given a number N, from the first man began to sound off, count to dequeue N,
* and then from the next person to start from 1 began to sound off again,
* count to stand out and N... So circulation, until (till) the final out all,
* out output trajectory
*
*/

Public class Test5 {
The static/store/M
List List=new LinkedList (a);
//a lap count after, temporary storage dequeue person
List TMP=new LinkedList (a);

Public Test5 (int m) {
For (int I=1; I & lt;=m; I++) {
List. Add (I + "");
}

}

/* *
* recursive implementation main body
* @ param start
* @ param n
*/
Public void start (int start, int n) {
Int size=list. The size ();
For (int I=1; I & lt;=the size; I++) {
If ((I + start) % n==0) {
System. The out. Print (list. Get (I - 1) + ", ");
TMP. The add (list. Get (I - 1));
}
}
//delete temporary queue in m
For (String STR: TMP) {
List. Remove (STR);
}
//remove the list
TMP. The clear ();
System. The out. Println ();
If (a list. The size () & lt; N) {
System.out.println(list);
return ;
}
//recursive
Start (+ start (size) % n, n);
}

Public static void main (String [] args) {
Long t1=System. CurrentTimeMillis ();
//M=100
Test5 tx=new Test5 (45);
//n=7
Tx. Start (0, 3);

System. The out. Print (" time: ");
System. The out. Println (System. CurrentTimeMillis () - t1);

}

}

CodePudding user response:

Online, just learned

CodePudding user response:

 package com. Wosai. Main; 

Import the Java. Util. ArrayList;
import java.util.Iterator;
Import the Java. Util. List;

/* *
* Created by qiumy on 2017/3/7.
* & lt; P/& gt;
* 45 kindergarten in a circle, 1 count off, clockwise from the monitor report 3 dequeue,
* the next starting from 1, back and forth so count off, after the last monitor is clockwise side which one of the class?
*/
Public class KidDemo {
Public static void main (String [] args) {
List Kids=new ArrayList (a);
//init
For (int I=0; I & lt; 45. I++) {
Kids. Add (I + 1);
}
//start
StartCount (kids, 0);
System. The out. Println (" last kinds "+ kids. The size ());
System. The out. Println (kids);
}

/* *
* @ param offset and the residue of the number of the last
*/
Public static void startCount (List Kids, int offset) {
If (kids. The size () & lt; 3) {
return;
}
Int nextOffset=(kids. The size () + offset) % 3.
For (int I=kids. The size () - 1; I & gt;=0; I -) {
If ((I + offset + 1) % 3==0) {
System. The out. Print (kids. Get (I) + "out");
Kids. Remove (I);
}
}
System. The out. Println ();
StartCount (kids, nextOffset);
}
}

CodePudding user response:

 import Java. Util. ArrayList; 

Public class Test8 {

Public static void main (String [] args) {
System. The out. Println (getNum (45));

}
Public static int getNum (int num) {
//assign ArrayList a number, starting from 1 until 45
ArrayList List=new ArrayList<> (a);
For (int I=1; I & lt; Num=; I++) {
List. Add (I);
}
//set a counter, starting from 1, circulation achieve + +, as long as the cycle may have been added in the
Int count=1;
//set cycle, cycle end conditions for the size of the list for 1.
for(int i=0; List. The size ()!=1; I++) {
//judgment value equal to the length of the list, I anew to assignment to make it back to the list of the origin, I started to count off again,
If (I==list. The size ()) {
I=0;
}
//in the remainder of a counter to take 3, equal to zero at the index of the list are number removed. Remember since I first minus one time here, because after removing elements, elements from the back can go into a,
If (count % 3==0) {
List. Remove (I -);
}
//counter since the add
count++;
}
Return the list. The get (0);
}
}

And studied a method of learning together.

CodePudding user response:

Don't understand!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

 
Package CSDN.

Import the Java. Util. ArrayList;
Import the Java. Util. LinkedList;
Import the Java. Util. List;

Public class Ring {

Public static ArrayList Ring (ArrayList IList, int index) {
If (iList. The size ()==1) {
Return the iList;
}

ArrayList NewList=new ArrayList (a);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related