(algorithm) Pirate loot _2

Source: Internet
Author: User

Share an interesting article (from Bole Online: http://blog.jobbole.com/70395/), the same pirate loot issue, this article in a humorous tone and easy-to-understand dialogue to explain the problem of pirate loot.

Unlike the previous blog post Pirate Loot _1, the voting rules here are half and not more than half. So the thought process of the problem is as follows:

(300,0)

(299,0,1)

(299,0,1,0)

(298,0,1,0,1)

(298,0,1,0,1,0)

The article reads as follows:

#算法题 # 6 Pirates are going to loot 300 gold. The rule is the number of the most qualified pirates to be presented to each individual, and then the whole vote. If the programme receives at least half of the agreed-upon vote, it is executed in accordance with the programme, otherwise the Pirates who propose the programme are killed and the remaining persons are the oldest to continue the programme. Pirates are smart enough to maximize profits if they can survive. Q. What was the result of the final loot?

This question is very interesting, the main test is a simplification of the problem of the thinking ability, similar to the middle school mathematics in the proof, first see whether N=0 is set up, and then assume that n-1 established, proving that N is also established.

If it really doesn't work from 6 people's point of view, it seems that everyone has a tendency to vote against the oldest pirates and then get their own points, but how much each person can divide and wonder.

Because there are so many changes, it is assumed that the pirates have thrown in a lot of money, killed four pirates, and finally left only two people.

This brings the plan to the old five. He looked at the left two people, that our own vote is 50%, do not care about the old six approve, too good! So according to the survival && profit maximization principle, he gave 300 gold coins to himself, the old six did not get anything, and a vote on the passage, he did not have any way.

Therefore, when the n=2, the algorithm is the first to determine the problem and stable results: (300,0). The following can be inverted n=3,4,5,6 situation.

Seeing this result, the old six dumbfounded. With their own mixed with a half-day nothing ah, but also killed the front to himself very good several predecessors, too lost! So old six prayed to God: "God, if you give me another chance, I will say to the old four: I vote you, if you have to give this sentence add a deadline, I hope it is 10,000 years!" ”

The words also coincidentally, God just passing by, hear so familiar and pious prayer, can't help heart born compassion, then appeared to them said: "Well, since you recite my good base friend Monkey King's lines, then I will meet you this request." ”

Old Wuyi Look out: "Ooooooh nooooooo! God, you can't be eccentric! ”

But God must be a decent person with identity card, is to talk about credibility and integrity. So all of a sudden the four dead pirates revived again and began redistributing the loot.

Lao Liu first muttered: "Old five is not a thing, the left two people bully me." This time, as long as the old four give me a gold coin, I will vote in favour! Anyway it is not my turn to divide, to the old five here game over ... "

Old Wuyi Listen urgently: "If so, old four can a big son do not give me to 2:1 vote number passed, do not do!" If old three give me a gold coin, I agree with old three, we both 50% vote, let old four old Liu du Hexibeifeng go! ”

Old four smirking said: "Don't make a fuss, you two want to black me, no way." This time I know there are old three in front, plus the old five and he was in cahoots, certainly not to my point. So, the second to give me a gold coin on the line, and then give the old Children's Day, so we three passed, hey, not the old three distribution on the end! ”

Old three anger: "The eldest is still alive!" The second count is God horse thing! Let the Boss divide! eldest brother to me and the old five each one gold, our elder brothers support you, 3 votes is enough, other people oppose also useless! ”

eldest brother hehe smile: "Really?" Your baby last time to kill me, I can believe you? ”

Old three crying said: "Eldest brother you do not remember the villain, last I was not also they killed it?" I will not support you this time I am a hammer, you want to Ah, the second point I can not get anything, you always give me a gold coin I have been grateful! ”

Old five also hurriedly table loyal: "Eldest brother you so decided, we if voted against on the turn to the second division, according to old four old six meaning, I and old three all have to Hexibeifeng Ah!" God is next to witness, if we two untrustworthy, go out to be killed by a car! ”

God grunted with disdain: "I am here also what car hit, I can get a piece of tofu to kill you believe it?" ”

Old three old five scared repeatedly nodded: "I believe, I believe!" ”

Second old four old Children's Day look at the situation is critical, shouting up: "Boss, these two boys can not believe Ah!" ”

The eldest brother looked at them: "Do not believe they believe you?" The most untrustworthy is the second, he is looking forward to my death good revenue streams, think I am stupid ah? Hum. ”

The second words, depressed to squat to the side of smoking. Old four old six still not reconciled: "eldest brother, Kill your dick must be the most earn, so he certainly voted against." But we're not too big look forward, are we? You'll get a gold coin at most. You do not give old three old five gold coins, to our, we vote you are the same two votes! ”

The boss thought to say: "No." If I die old and second points, you can also get a gold coin, so I want to give you a gold coin for you no difference, unless I give you two gold coins to ensure that you do not anti-water. But it is better to give old three old five a gold cost. Hey, you do not fool me, I died a time now learn to behave! ”

The more he heard the more confused, the more impatient he interrupted them: "What are you talking about?" Play logic is not? Bullying our liberal arts students? hurriedly, 1000 years ago I had an appointment with the Monkey King to go to the tower with the star to play, there are a hundred thousand of light-years to catch the mountain, there is no time to listen to you here nonsense. ”

The eldest brother looked at the overall situation has been decided, so solemnly cough a sound, said: "That Lao Tzu to mention." Second old four old six get 0, old three old five get 1, Lao Zi take 298. ”

Dick old Four old six naturally not dry, all voted against. Old three old five voted in favour, plus the eldest one vote, just 50% agree, so six pirates divided the booty, the mood of each other off.

Only God stayed where he was, and the result was quite unexpected! After 100 years, he finally figured it out, and said to himself, "algorithm is a very profound knowledge!" Should learn to study well! ”

So God took out the mobile phone, online bought the original "algorithm design Manual", and then to the Monkey King called: "Hello Lao Sun Sorry, I do not have to play football." What's the matter? Well, I have to go back and learn the algorithm .... "

(algorithm) Pirate loot _2

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.