Java implementation Joseph Ring: 50 people in a circle count, a number of 3 of the people quit, begging for the last remaining number of people

Source: Internet
Author: User



public class Main {public static void main (string[] args) {//50 persons, starting from the first person, counting to 3 of the people are Countthree (50, 0, 3);} /** * Joseph Ring: Known n individuals (denoted by numbers 1,2,3...N respectively) sit around a round table. * From the number of people numbered K began to count, the number to m of the person out of the man, and his next person from 1 began to count, * the number to M of the person again, according to this rule repeat until the round table all the people out. *  * @param n Total number of people * @param start sequence number starting off, start < n * @param m dequeue mark (can be greater than n) */private static void Countthree (int n, in t start, int m) {list<integer> list = new arraylist<integer> ();//Initialize list for (int i = 1; I <= n; i++) {List.ad D (i);} while (List.size () > 0) {//will be previously connected to the end of the list for (int j = 0; J < M-1; J + +) {List.add (List.remove (start));} Print the ordinal System.out.println (List.remove (start)) of the Dequeue;}}


Java implementation Joseph Ring: 50 people in a circle count, a number of 3 of the people quit, begging for the last remaining number of people

Related Article

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.