1000 bottles of water found the toxic bottle, the onset of toxicity after a week, the minimum number of rats required within a week

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/zzran/article/details/8083386

The full text is as follows:

This is the application of bit, 1000 is close to 1024, so 10 bit bits are required to number the bottle, from 0 to 999. In this case, 10 mice are required. The bottle numbers are:

000,00000

00000,00001

000,00010,

000,00101

00000,00111

......

11111,00111

At the same time, give the mouse number, starting from 1, 2,... 10, starting from the low level, let the N rats drink the medicine in the n bit as 1 bottle. A week later, if none of the mice had been infected, the first bottle would be toxic. If some mice had been infected, the first bit would be 1, and the other would be 0. After it is changed to an integer, the corresponding number is the number of the toxic potion.

 

For your own understanding, attach a simple example. If there are four bottles of water, one of which is toxic, you only need two mice according to the above algorithm, for example.

Let the mouse drink all the water from the bottle containing 1 in the column, that is, the right mouse drank 1 or 3 bottles of water, and the left mouse drank 2 or 3 bottles of water, because 1st bottles of water are toxic, then the right mouse is poisoned.

The red is the poisoned mouse, and the white is the normal mouse. Finally, the red mouse is located at the bit position 1, and the white mouse is located at the zeroth, which is a toxic bottle number.

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.