Flyinghearts book notes serialized in the beauty of programming (17)

Source: Internet
Author: User

4.1 _ Question about plane seat at King Kong

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, among the N seats, if King Kong chooses his own seat or the selected seat is behind the I seat (n-I seats meet this condition ), then I will certainly be able to sit in the original seat. If the selected seat is in front of I, assuming J, then the J passenger will not sit in the seat of King Kong, otherwise, another person's seat will be snatched. Because his behavior is similar to that of King Kong, he can be treated as King Kong and the first J seats will be removed, the remaining seats and passengers are numbered again from 1 according to the original size. Then, the seat number of the first passenger is changed to I-J, and the total number of new seats is changed to n-J. Therefore, 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 <j, g (I, n) = f (I, n) = (n-I)/(n + 1-I ).

If I> J, g (I, n) = f (I-1, n) = (n + 1-I)/(n + 2-I ).

Similar question: "Joseph ring: N people, numbered 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 ."

 

From: http://blog.csdn.net/flyinghearts/archive/2010/05/19/5605994.aspx

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.