There are 1,000 bottles of drugs, but one of them is poisonous. Rats will die within a week after taking any amount of poisonous potion! Excuse me, how many mice are required to find toxic drugs in one week?

In the programmer interview, the interviewer sometimes tests some of our computer programming intelligence questions. This is an interesting intelligence question. This question examines our flexible use of bits.
Firstly, 1000 and 1024 are almost the same, so we can use 10 bits to number the 1000 bottles of medicine, that is, convert the number of the nth bottle of medicine into the corresponding binary.
Insert picture description here
Then we take 10 empty bottles and number them as (10)(9)(8)(7)(6)(5)(4)(3)(2)(1). Put one drop of potion from each bottle with the first binary number (the first one on the right) as 1 into the bottle numbered (1), and put one drop of potion from each bottle with the second binary number as 1 Enter the bottle numbered (2), and so on.
Finally, use 10 mice numbered 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 to drink the potion corresponding to the numbered bottle, and check the survival of the mice one week later.
Insert picture description here
One week later, the corresponding position of the dead mouse is 1, and the corresponding position of the surviving mouse is 0, so a binary number is formed, and the decimal number corresponding to the corresponding binary number is the number of the bottle of toxic drug.
So what is the reason for this? Because the mouse will die within a week if he takes any amount of poisonous potion, and as long as he drinks the potion with the binary digit of 1 corresponding to the poisonous potion number, the rat will definitely die. Drink the binary corresponding to the poisonous potion number. The mouse with the 0-digit potion will not die, so the final binary number formed by the mouse corresponds to the bottle of poisonous potion.

Guess you like

Origin blog.csdn.net/chenlong_cxy/article/details/113057754