Java (original)

Source: Internet
Author: User

Java

My daughter was ill and stayed in the hospital for a few days. When I worried about my daughter, I also felt deeply the greatness of Medical industrialization. Under the guidance of all the great spirits that it showed to money, the enthusiasm of doctors has been improved unprecedentedly. "Open thinking and positive income generation" has become a hot topic in hospitals. I think everyone has also discovered this situation, that is, "No disease is regarded as much disease, no small disease is regarded as much serious disease, and a serious illness is more serious ". In order to let everyone see the onset of the disease, is it time for medical industrialization to let it go, but it is still time for the hospital to become holy.

When it comes to leaving, I can't help but think of an algorithm problem in programming:

It is said that there are 10 children playing games in a circle, starting from 3rd children, counting clockwise, every time they count to 5th children, the child leaves. The children keep leaving and the circle is shrinking. The last child is the winner. It may be said that this is not a problem with Joseph.

Yes, this is the problem with Joseph. Do you know the story of this problem?

The Joseph PHUs problem is based on a report by the historian Joseph Ben Matthias (become Joseph PHUs, the report tells about a suicide agreement he signed with 40 soldiers during the period when they were surrounded by the Roman army in 67 a.m. Joseph suggested that everyone should kill his neighbors, he was wise enough to make himself the last of these people, so he was born again. Oh, do you think this person is really bad.

Now let's look at the specific Algorithm Implementation of the Joseph PHUs problem.

Public class Joseph PHUs {

Public static void main (string ARGs [])

{

Int num = 10; // Total number of children

Int interval = 5; // interval each time, the child is left.

Int [] child = new int [num + 1]; // child tree Group

Int [] flag = new int [num + 1]; // indicates whether each child is in the circle. 1: 0: Not

For (INT I = 1; I <= num; I ++ ){

Child [I] = I;

Flag [I] = 1; // each child starts to be In the circle

System. Out. println ("no." + I + "Name of the child:" + child [I]);

}

Int n = 0;

Int I = 3; // The first few children

Int J = 1; // starts from 1

Boolean noend = true; // indicates whether the flag ends.

While (noend)

{

While (j <interval ){

I = (I + 1> num? 1: I + 1 );

J + = Flag [I];

}

Flag [I] = 0;

N ++;

If (n = num ){

Noend = false;

System. Out. println ("the" + I + "last child victory ");

}

Else {

System. Out. println ("no." + I + "children leaving ");

J = 0; // when J reaches interval, start counting again

}

}

}

}

You can try to change the number. Looking at the execution results, I always think there seems to be some rule, but I haven't summarized it yet. If that friend can summarize it, I hope it will be known to everyone.

Finally, let's give the following sentences to everyone to end the gift.

The hospital is not a cinema. You can see it without looking at it.

Hospitals are not welfare homes. They can take them if they don't want,

Hospitals are not nursing homes.

The hospital is not a State Council, and can be accessed without any intention.

 

 

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.