The beauty of programming Reading Notes 13: 4.1 question about plane riding with King Kong

Source: Internet
Author: User

The beauty of programming Reading Notes 13:4.1Diamond flight problems

 

Problem:

A plane is about to take off now. Passengers are preparing to follow the ticket number (1, 2, 3,... N) queuing for boarding in turn. Suddenly a gorilla (Yes, his name is King Kong) came ). He also had plane tickets, but he jumped into the first plane and sat down at random. According to the degree of social harmony, other passengers have two reactions:

1.All the passengers were angry and said, "Since Comrade Kong does not comply with the rules, why should I comply with them ?" They also sat down at random and refused to give seats to other passengers.

2.Although the passengers are angry, they still focus on "Harmony". If their position is not occupied, sit down quickly. If their position has been occupied by others (or Comrade Kong, just randomly select another location to sit down and start to close your eyes and raise your mind.

In both casesIWhat is the probability that a passenger (except Comrade King Kong) will sit at his original ticket?

 

Set the total number of seats to N:

For question 1, each person chooses a random seat. The probability of any person sitting in a specified seat is the same. Therefore, the probability of the first passenger sitting in his seat is 1/N.

Question 2: the answer is related to the original seat number of King Kong. Remove the seats of King Kong and rename the passengers (according to the air ticket number) and the remaining seats in the order of the original size from 1.F (I, n) indicates the probability that the new I-th passenger will sit in his original seat in the new arrangement (n-1 passenger seats and the original seat of King Kong,In N seats:

① If King Kong chooses his own seat or the selected seat is behind the first seat (n-I seats in total meet this condition ), then the first passenger will surely be able to sit in the original seat;

② If the selected seat is in front of the I-th seat, assuming J, then the J-th passenger will grab the seats of others unless sitting in the seat of King Kong, because he acts like King Kong, he can be treated as King Kong. Remove the first J seats, and the remaining seats and passengers are sorted by the original size and numbered from 1. Then, the seat number of the previous I-th passenger is changed to I-j, the new total number of seats is changed to n-J. The formula is as follows:

UseG (I, n)Indicates the probability that the first passenger will sit in his seat in the original arrangement. Assume that the seat number of King Kong is J.

If I <JG (I, n) = f (I, n) = (n-I)/(n + 1-I).

IfI> JThenG (I, n) = f (I-1, n) = (n + 1-I)/(n + 2-I).

 

 

Similar questions:

"Joseph ring: N people, numbered from 0 to n-1, in a circle, starting from 0, reporting from 1, all reporting to M columns, the next person continues reporting data starting from 1. Find the number of the last person ."

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.