[Mathematical problems] poison and mouse research [turn]

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/icyJ/p/Mouse_Poison.html

Base:1. Binary Expressions for integers
 +/2= ---(Yu)--0 -/2= ---(Yu)--0 -/2= the--(Yu)--0 the/2= +--(Yu)--1 +/2= to--(Yu)--0 to/2= the--(Yu)--1 the/2=7--(Yu)--17/2=3--(Yu)--13/2=1--(Yu)--11/2=0--(Yu)--1

1000 binary expressions are 1111101000 = 29 + 28 + 27 + 26 + 25 + 23 = 512 + 256 + 128 + 64 +32 + 8

2. What is the relationship between the binary and the above topics?

An integer value that expresses the 0~2w-1, which requires only the binary of the W bit.

Convert again: The binary of W bit can Express (2w-1) +1=2w integer value.

Question: 8 Bottles of water, one of which is poisonous, how many mice do I need to test?

Step One: 8 = (binary) 1000 = 23.

That is, three-bit binary can express 8 cases.

Step Two: List all the three-bit binaries and exclude 0 of the situation

The computer's integer (index) starting from 0, the life of the counting habit starts from 1, here can take a coincidence, the 0 is understood as index, map to the last number, here is 8, eliminate 0, that is, the elimination of the 8th bottle of water situation.

┆0┆0┆1┆//1┆0┆1┆0┆//2┆0┆1┆1┆//3┆1┆0┆0┆//4┆1┆0┆1┆//5┆1┆1┆0┆//6┆1┆1┆1┆//7

From right to left, the first column corresponds to 1010101, where 1 corresponds to {1,3,5,7}, and the second column corresponds to the third column of 0110011=>{2,3,6,7}; 0001111=>{4,5,6,7}

Step Three: Extract the above numbers to obtain the results.

The first mouse fed him (1,3,5,7) the mixture of bottles of water, the second mouse fed (2,3,6,7), the third mouse Fed (4,5,6,7) the mixture.

Step four: Calculate the answer based on the results.

If the first one is dead, the second and the third are alive, we still write from right to left 001 (dead to 1, 0 alive), and a decimal integer of 1. So the conclusion is that the 1th bottle of water is poisonous.

If the first one dies, the third one dies, and the second one is alive. Binary is 101, and go decimal is 5. So the conclusion is that the 5th bottle of water is poisonous.

If all died. 111, corresponding to 7, then the 7th bottle of water is poisonous.

If it all survives. 000, that's 0 bottles of water (or, understandably, we also say the 8th bottle of water.) The integer in the computer starts at 0, while the actual operation starts at 1. When you do this type of question, turn 0 into the last one to be toxic.

Step Five: Verify the answer.

101 Situation: The second survival, stating that 2,3,6,7 no problem, and the first and third, take their intersection, it is possible 5 and 7, but the previous has ruled out 7, so the answer is 5.

Again to verify the situation of 110: The first surviving, 二、三只 glorious, indicating that 1,3,5,7 no problem, after two of the mixed liquid to take the intersection, there may be 6, 7. 7 is excluded and the answer is only 6.

Continue thinking:

1000 bottles of water, find out the poison of the bottle of water, how many mice need, how to do the actual operation?

< < 210 so the number of white mice required is 10, that is, 10 mice can fully respond to 1000 cases. Of course, 10 mice can reflect the maximum number of cases, it should be 210=1024 species.

The result is that 10 mice are needed, and the next 10 mice should be able to come to a conclusion.

0000000001------1

0000000010------2

0000000011------3

0000000100------4

0000000101------5

...

1111100111------999

So the first rat should drink 1,3,5,7,9,11,..., 997,999 bottles of water.

The second mouse is the 2,3,6,7,..., 998,999 bottles of water.

The third mouse is the 4,5,6,7,12,13,14,15,..., 996,997,998,999 bottles of water.

...

The tenth mouse is the 512,513,514,..., 999 bottles of water.

Well, each mouse indicator is a mixture of nearly 500 bottles, which is natural, with 0 and 12 possibilities per bit. So much, the mice were probably drinking to death. Also think of a problem ah, dilution so serious, can poison rats? These days the vitality of the mouse is very tenacious ah, this good poison ah ...

...... Finally, the mouse's sacrifice, from right to left, dead to 1, alive for 0, get the final binary expression, and then converted to decimal, that is the answer to the poisonous bottle.

Problem: 6 of equal quality of the ball and a slightly heavier balls, can not use the balance, can only be called, design a method, only three times to find a slightly heavier ball.

A similar problem, here the number becomes 7. The test data is also changed from dead to heavy and light, but the same can be converted to 0 and 1.

If you can read the above, think about the answer to this.

[Mathematical problems] poison and mouse research [turn]

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.