The Joseph Ring problem is about ,n A circle of individuals , From k Individuals start counting in one direction , Report to No m Personal time , The first m Personal listing , From the next person next to you ( Not listed ) Start , Find the order of people in the whole ring . Here is what I use java Solution to the problem .

 class JosephLoop
{ //n Is the number of people in the ring ,m For the number of people who count each time ,k Is the starting position of the count 0~n-1
int n,m,k;
int[] persons;
int[] seq;
JosephLoop(int n, int k, int m){
this.n = n;
this.m = m;
this.k = k;
persons = new int[n];
seq = new int[n];
}
public void showSeq(){
for (int x:seq )
{
System.out.print(x+" ");
}
}
public void calcLoop(){
for(int j=0;j<n;j++)
{
int index=k;
for (int i=0; i<m ; index++)
{
if (persons[index%n]==0)
{
i++;
}
}
persons[(index-1)%n] = 1;
seq[j] = (index-1)%n;
k = (index)%n;
}
}
}
 class LoopTest
{
public static void main(String[] args)
{
JosephLoop jose = new JosephLoop(12,5,4); //n,k,m
jose.calcLoop();
jose.showSeq();
}
}

Joseph Ring problem -Java Array to solve more related articles

  1. Joseph's ring java solve

    in total 3 Solution ,1. Mathematical derivation ,2. Use ArrayList Recursive solution ,3. Use the first connected LinkedList solve import java.util.ArrayList; /** * Joseph Ring problem * Need to be ...

  2. Joseph ring --- object-oriented --- java Code

    Joseph ring Of object-oriented solution After the Romans took jotapat ,39 Jews and Josephus And his friends in a cave ,39 A Jew decided to die rather than be caught by the enemy , So I decided to commit suicide ,41 Individuals in a circle , From the first 1 individual ...

  3. Joseph ring (java Object oriented implementation )

    /* * author :zhaop * function : Joseph ring * */ public class Joseph { public static void main(String[] args) { // TODO ...

  4. Joseph's ring java Realization

    from :http://www.cnblogs.com/timeng/p/3335162.html Joseph ring : It is known that n personal ( To number 1,2,3...n respectively ) Sit around a round table . From the number k People began to count , Count to ...

  5. Joseph ring (java)

    Problem description :n A circle of individuals , every other k One to kill one , Ask the number of the last survivor Suppose the label is 0 ~ n-1, The survivors are f[n] 1. A special case :f[1]=0 2. General situation :f[n] = (f[n-1]+k)%n Game begins ...

  6. C Language array implementation Joseph Ring problem , And time complexity analysis of it

    Try to express I try to express Joseph Ring problem : A group of people in a circle , Make such a game , Choose a person as the starting point and the direction of counting , This man counts first 1, To the next person 2, Until the person who counts the number agreed in the rules of the game , For example 3, Count to 3 The man who's in charge is leaving here ...

  7. hdu 1443 Joseph【 Joseph ring 】

    subject The question : Altogether 2k personal , Respectively k A good man and k I'm a bad guy , Now we need to every m One person picked out the bad guys , But the condition is that no good person can be picked out before the last bad person is picked out .. Ask the smallest m How much is the Joseph Ring problem , Usually when we solve this kind of problem, we compile ...

  8. j Using arrays to implement Josephus rings java

    Let's first look at the Joseph Ring problem : Given m personal ,m A circle of individuals , Given a number n, from m The first person in a person, every n The individual removes it , Ask for the number of the last person to go out . Ideas : Create a length of m+1 Array of , Initialize its contents ...

  9. Loop list of Java Realization , Solve the Joseph Ring problem

    import java.util.Scanner; /** * Loop list of Java Realization , Solve the Joseph Ring problem * * @author LIU * */ public class LinkedList { ...

Random recommendation

  1. The first step of wechat background development :nodeJS+express Access to wechat background detailed tutorial

    Blog by   Waterwheel   To write Welcome to correct , Please take the link with you ——http://www.cnblogs.com/xuange306/p/4971702.html Preparatory work 1: If you don't have a server , Then you need a ...

  2. [ problem ] UISearchBar Click Cancel to skip the question

    Details of the problem : First of all TableView As NavigationController Of RootViewContrller, then UISearchBar   Add to TableView Of headV ...

  3. SQL Categorical statistical functions

    SELECT TransactionNumber,SUM(CASE WHEN ReasonLevel=0 THEN           TransactionNumber ELSE 0 end ) a ...

  4. [CLR via C#]13. Interface

    One . Class and interface inheritance stay Microsoft.Net Framwork in , There is one named System.Object Class , It defines the 4 A common instance method :ToString, Equals, GetHashCode and Ge ...

  5. A profound MVC Simple web pages

    Last time we created the first MVC Website , It didn't work , This time it's easy to run , First of all, we need to understand MVC What's the relationship between patterns . I won't say much about it here , Create a web page directly , Used to display some data , If I want to create a database, I will create it first , For convenience ...

  6. JS There are two types of data , Do you know ?

    Daniel, please ignore this article ! JS It is mainly divided into basic data type and reference data type , There's a big difference between the two , After reading this article, you will make progress , Let's get to the point First, let's look at the basic data types ( I won't talk about the concept , Go straight to the code ): var i = 10: var ...

  7. Android Make up animation notes

    Layout file : <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...

  8. vue Start and go --“ Installation chapter ”

    Before explanation , I have to say something here , It's not easy for rookies to start installing these things , All kinds of crazy Baidu , Search for .( Looking for my tears are almost streaming down ), Don't say nonsense , Get serious . First step : Construction of environment : vue Recommended development environment : Node.js: ...

  9. 《Google SRE》 Journal entry

    notes : This is a reading note on last year's national day , There have been frequent failures on the line recently , Reread this Reading Note , Think <Google SRE> excellent , So I moved from the simple book to the blog Garden , I hope you will benefit . My profile address :daoqidelv National Day ...

  10. 【Python】easygui Little turtle

    The translation is adapted from the official document :http://easygui.sourceforge.net/tutorial/index.html Translation adaptations : Little turtle , Welcome to reprint , Please ensure the integrity of the original ! Demonstrate the use of Pyth ...