1000 bottles of liquid 10 white mice interview questions answer, 1000 bottles of questions answer
Reprinted please indicate the source: http://blog.csdn.net/xiaojimanman/article/details/45917689
Http://www.llwjy.com/blogdetail/1cee085f07d9f8b59c35df384b30fccc.html
The personal blog website has been launched. Its website is www.llwjy.com ~ Thank you ~
Bytes -------------------------------------------------------------------------------------------------
In the last blog, I left a white mouse interview question. Here is the final answer.
Problem description
There are 1000 bottles of liquid (normal, non-toxic), but due to staff mistakes, the poison is dropped into one of the bottles, we can't tell from the appearance and smell that the drug was contaminated. We only know that the toxic period of this drug is 7 days, and there are 10 mice in the laboratory, how can I know which bottle is contaminated only after 7 days?
Solution
1) We will number 1000 bottles of liquid 1 ~ 1000, and then convert the number into a 10-bit binary, for example, 1 is 0000000001;
2) numbers 10 mice 1 ~ 10;
3) give the binary number of the liquid to the corresponding mouse, for example, the liquid number is 1111100000, that is 1 ~ No. 5 mice do not drink this bottle of liquid, 6 ~ On the 10th, the white mouse drank this bottle of liquid;
4) after one week, observe the death of the mouse ~ No. 5 dead mice, 6 ~ When the mice were alive on the 10th, the binary code of the toxic bottle of liquid was 0000011111;
5) convert the binary code obtained in Step 4 to decimal. Here is the 31st, so we can infer that the liquid numbered 31 is contaminated.
Bytes -------------------------------------------------------------------------------------------------
Small benefits
Bytes -------------------------------------------------------------------------------------------------
I have already launched the Lucene case development course at geek College (now the first course is available ~
Lesson 1: Lucene Overview