Tian Ping called the ball problem
Tianping said that there are many classic paradigm solutions to the ball problem. Here we are talking about only the most widely used triplicate encoding solution.
Why do you think of using a triplicate system? In fact, it is easy to understand. Let's consider the status of the ball: not placed on the balance, on the left of the balance, on the right of the balance. We may wish to use some numbers to express these three states:
0 -- not on the Balance
1 -- left disk on the Balance
2 -- placed on the right disk of the balance
In this way, we can use a digital string to represent the Weighing Process of a ball. For example, if the encoding of a ball is 210120, it indicates that the ball was first weighed on the right disk, the second time is on the left disk, the third time is not on the balance, the fourth time is on the left disk, the fifth time is on the right disk, and the sixth time is not on the balance. It's easy. Just use a digital string to express the complicated Weighing Process of the ball.
For convenience, we will describe this problem with "12 small balls named 3 times". However, you can easily promote it to "m small balls named N times ". Good. I want to talk about it in plain text.
Let us assume that we have compiled 12 small balls in a three-digit encoding that is not repeated. During the weighing process, we fully follow the encoding steps: Step 1, we put the encoding 0th bits on the 12 small balls as 1 on the left side of the balance, encoding 0th bits as 2 on the right side of the balance, encoding 0th bits as 0 is not placed on the balance, write down the weighing result. In Step 1, we put the encoding 1st bits for 12 small balls on the left side of the balance, and the encoding 1st bits for 2 on the right side of the balance, if the number of digits coded with 0th bits is 1 is not placed on the balance, the weighing result is recorded. If the number of digits is N, the number of digits is weighed n times to obtain n sets of results.
The status of the result is as follows: Balance of the balance, light on the left of the balance to the right, and heavy on the left of the balance to the right. Why? There are also three types. (HIA, unfortunately it's not a book, but the drama is still behind) We use 0 to represent the balance, 1 to the left to the right, 2 to the left to the right; in this way, after weighing n times, we get an N-bit result code, which is also a three-digit code. Note: This encoding may be the same as the encoding of a small ball! :)
You seem to have realized something. Okay, now let's pick out the problem: the resulting code is the same as the non-standard ball code or has a direct correspondence. (What is the relationship? )
If we determine the weighing method for a group of small balls (corresponding to the 3-digit encoding of the 12 small balls), we will consider it in turn, it turns out that the ball on the left disk of a certain scale is now placed on the right disk of the scale. The ball on the left disk of the scale is now placed on the right disk of the scale. The ball on the scale should not be placed on the scale. So will the ball code (also 12) be duplicated with the original one? Obviously there are no duplicates. The encoding obtained from this correspondence is called an even code (the next definition here is to change every digit in the encoding, 1 to 2 and 2 to 1 and 0, get the new Code called the original code. For example, the 22102 or 11201 pair code is 22101, or the 11201 and pairs are the same ). At this time, you will consider the question-how many three-digit 3-hexadecimal codes are there? The answer is 3 ^ 3 = 27 (recorded as 3 ^ N), which is 3 more than the 24 encoding mentioned above. Why study this symmetric code? Because we put the, B, C, and D balls on the left disk, and put the', B ', C', and d' balls on the right disk -- and we put A', B ', the C ', d' Balls are placed on the left disk, and the, B, C, and D balls are placed on the right disk. The weighing meaning is the same and the results are the same, we need to avoid repeated operations. Therefore, to implement this algorithm, it is very important to select the code -- select one of the pair codes to numbers the ball.
Here, I think you must have guessed it. What is the three more codes than the preceding 24 codes? They are 000,111,222. 111 and itself are parity codes, and 222 and are mutual parity codes. Why remove the three of them? I don't want to explain it here. To solve this problem, you have to take a look at the mathematical proof later!
Therefore, we come to the conclusion that if a group of three hexadecimal codes are correctly selected to numbers the ball respectively, The results code obtained by strictly following the Weighing Process of the ball encoding are, it must be a non-standard ball code or a pair code. (Because the encoding of any two balls is not an even code, our weighing operation uniquely identifies a non-standard ball) the proof method of this conclusion is too complex (I typed 4 pages in Word), so I put it in the text for packaging and download.
The following describes the specific process of code implementation by the program.
For reference, we first obtain a code array to store the encoding. To save space, the Code array in my program stores the decimal encoding. I use gettheball. num2code () and gettheball. code2num () to implement the mutual conversion between the tridecimal System and the decimal system. First, we store all the codes in the array, then remove the three codes 000,111,222, and then delete half of the remaining codes. Then we can mark the 12 codes to the ball. For the encoding at the beginning of 1, we choose all the encoding codes greater than 111. For the encoding at the beginning of 2, we move the parity code of "the part we selected at the beginning of 1, for the encoding starting with 0, we choose from the left-to-right encoding bits. the first digit that is not 0 is 1 encoding (this is like hard to understand, in fact, the first digital that is not 0 is not 1 or 2, And we deleted the half of 2 ).
Okay, let's look at the number. We are optimistic that we have half of the total deleted. According to the encoding method, the result code obtained after the operation, if in the ball encoding, that encoding ball is a non-standard ball, and lighter than the standard ball. If the result code is not in the ball encoding, The result code is a non-standard ball pair code, and the non-standard ball is heavier than the standard ball.
Now, it's time to come to an end. In fact, to fully understand the meaning of this algorithm, why is it so encoded? Why is it correct? It must be proved by strict mathematics.
I used the three-in-one method to solve the small ball problem that Tianping called. I had to do this with my brother an Xinghua. The mathematical proof attached to this article is not done by myself. It may be due to a COI National Team expert, I don't know the author's name or surname. The article is also a mess and may be incorrect. It is here to provide some information for beginners. If you find any problems, contact me if you know the source and author of the original.
My source code (Java version)
Related mathematical proofs