Fun algorithms: Virus Testing for rats

Source: Internet
Author: User
Everyone should have heard of this old question: there are 1000 identical bottles, 999 of which are common water and one bottle is poison. Any creature that drinks the poison will die after a week. Now, you only have 10 mice and a week. how can you determine which bottle contains toxic drugs? The answer to this question is also classic: numbers the bottle from 0 to 999, and converts all the numbers to 10-bit binary numbers.

Everyone should have heard of this old question: there are 1000 identical bottles, 999 of which are common water and one bottle is poison. Any creature that drinks the poison will die after a week. Now, you only have 10 mice and a week. how can you determine which bottle contains toxic drugs?

The answer to this question is also classic: numbers the bottle from 0 to 999, and converts all the numbers to 10-bit binary numbers. Let the first mouse drink all the binary numbers from 1 to 1000, the first one is the bottle of 1, let the second mouse drink all the binary numbers, the right one is the bottle of 1, and so on. A week later, if the first mouse is dead, it will know that the first digit in the binary number of the poison bottle is 1 from the right; if the second mouse is not dead, in the binary number of the poison bottle, the second digit from the right is 0 ...... Every mouse's life and death can determine one of the 10 binary numbers, so that you can know the number of the poison bottle.

Now, the interesting question is: if you have two weeks (in other words, you can perform two rounds of experiments), how many mice do you need to find the poison from 1000 bottles? Note: The Mouse that died in the first round of the experiment cannot continue to participate in the second experiment.

Answer: seven mice are enough. In fact, 7 mice are enough to go from 3 ^ 7? = Found the poison in the first 2187 bottles. First, all the bottles are numbered from 0 to 2186, and then all are converted to seven-digit three-digit numbers. Now, let the first mouse drink all the three-in-order numbers from the right to the first to the second bottle, let the second mouse drink all the three-in-order numbers from the right to the second bottle, and so on. A week later, if the first mouse is dead, it will know that the third serial number of the poison bottle, the first from the right is 2; if the second mouse is not dead, in the three-digit serial number of the poison bottle, the second digit from the right is not 2, which may only be 0 or 1 ...... That is to say, each dead mouse is determined by its own life. the one in the three-digit serial number is 2, but each living mouse can only be determined, the one it is responsible for is not 2. As a result, the problem is due to only one week. In the second round of the experiment, let every living mouse continue his unfinished tasks and drink all the bottles that he is responsible. In a week, the three-digit serial number of the poison bottle will be revealed.

Similarly, we can prove that the t week of n mice can be changed from (t + 1) ^ n? Check the poison in the bottle.

Conclusion: Time for resources (rats ).

This article is available at http://www.nowamagic.net/librarys/veda/detail/1834.

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.