Find the prize that will be moved

Source: Internet
Author: User

Problem:

There are n bottles and one prize. players need to guess which bottle the prize belongs.

There are n black bottles (so that the game can't see whether there is anything in the bottle) from 0 to n-1 number, one line open.
If a gamer guesses a mistake, the prize will be moved to the left or right bottle with a probability of 50%.
When the prize is on the leftmost or rightmost side and the gamer guesses the mistake, the prize must be shifted to or left.

How many times do gamers have to guess the prize location.

PS: It seems like a Netease game interview question, which is interesting.



Analysis:

At first glance, it seems like there is no solution, and it is impossible to guess. This is also interesting.

Assume 8 bottles, 1.2.3.4.5.6.7.8

1) assume that the prize is in an odd number, for example, in 3.

First in order to point, 1 point once, no point 2, 1 point to the end, that is, 8 times.
No, the prize is even. Point 2, no, the prize is odd and cannot be 1. To change 1, you must pass 2, but 2 does not.

Therefore, the prize is an odd number after 3 or 3. Now at, if there is no prize, it is changed to an even number and cannot be 2. The reason is the same.


In this way, the prize will surely be found at the end of the order. If it is not found, the assumption is not true. The prize is initially in an even number.

2) assume that the prize is in an even number, for example, in 4.

Then we can start from 2. The principle is the same as above. We can certainly find it. Otherwise, the assumption is not true.

Scan twice to find the prize!

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.