Problem Prototypes:
Legend has it that in a long time ago, a plane carrying N-man had malfunctioned and made a landing on a deserted island. After the plane was completely scrapped, these people used the wreckage of the plane to build a boat that could only hold one person, so how to determine which of the N individuals is eligible to go aboard? thus, the N-person adopted the following way to solve this Dilemma.
Problem Description:
Suppose there are n individuals in a circle, and each has a unique sequential number from 1 to N. next, the number of people numbered 1 starts to count off. The man with the m number exits the Circle. Then by the next person from 1 to start a count, so the cycle, then finally left to the number of the person?
Import java.util.Scanner;
public class out{
public static void main (String Args[])
{
Out Out=new out ();
Receive user input, get the number of people in the dequeue n
Scanner sc=new Scanner (system.in);
System.out.println ("please Enter the total number of participants:");
int n= Sc.nextint ();
Receive user input, get the number of people in the dequeue m
System.out.println ("please Enter the number of the Dequeue person:");
int M=sc.nextint ();
Creates an array of Boolean types with a total number of characters
Boolean rs[]=new boolean[n];
Initializes a Boolean array with the initial value true
For (int I=0;i<n;i++) {
rs[i]=true;
}
int n=n;//remaining Number of people
Number of int m=0;//
Out.save ();
Print out the number of the last person left
For (int K=0;k<n;k++) {
If (rs[k]) {
System.out.println ("remainder" + (k+1) + "personal");
Break
}
}
}
public void Save () {
While (n>1)
For (int J=0;j<n;j++) {
If (r[j]) {
m++;
If (m==m) {
m=0;
rs[j]=false;
n--;
}
}
}
}
Joseph Ring Code Implementation in Java