This article was originally published in my technical blog at javaeye.
One of the 12 table tennis balls (or gold coins) is a defective item. The weight is different from that of other balls (but I don't know whether it is light or heavy, it can be called several times to see which ball is a bad ball.
This question was published on the BBS of the University a long time ago. I cannot find it, and it is not difficult to write it again.
Actually can be called 14 balls, the following is the solution (set as a A1-A14 ).
Note: The premise of 14 balls is that there is one more standard ball A0. Otherwise, only 13 balls can be called.
A0-A4 vs A5-A9
If they are equal, the bad ball is in the A10-A14 of the five balls.
5 balls (record to make A1-A5 plus a A0 for standard balls) the name is as follows:
A0, A1 vs A2, A3
If they are equal, the bad ball is A4 or A5, and one of them can be called once again with A0 (this does not need to be said, everyone knows how to name it ).
If not, assume A0, A1> A2, A3 (<, the following judgment is reversed), then it is called again:
A2 vs A3
If they are equal, the bad ball is A1. Otherwise, A1 is a good ball. The Bad ball is A2 and A3. Based on the last weighing result, it can be determined that the bad ball is lighter than the standard ball, so the result of A2 vs A3 is a bad ball.
If you weigh for the first time, then the bad ball is in the 9 balls of the A1-A9, And you know an unequal relationship, we assume that it is a A0-A4> A5-A9 (<, the following statements are reversed ).
Then test A1, A2, A5 vs A3, A4, A6.
If they are the same, the bad ball is in A7, A8, and A9, And you can export the light ball from it. The bad one can be found again.
If A1, A2, A5> A3, A4, A6
The Bad ball is in A1, A2, A6, and A1, A2> A0, A6 can be exported.
On the contrary, the bad ball is in A5, A3, and A4, and A5, a0 <A3, A4 can be exported.
It is not hard to see that the two cases are actually equivalent. You only need to compare the two balls on the same side to determine which one is a bad ball.
If there is no standard ball A0, then the first weighing cannot be 5 to 5, only 4 to 4, so a maximum of 13 balls can be called. The first equality is exactly the same as the previous one. If there is no difference, there is a problem with the eight balls, and there is one less than the first nine balls, so you can definitely name them. So why are all common questions 12 goals? It is estimated that few people really understand this question from the theoretical (Information Theory) when it was first circulated, so the answer is all made up, and it is naturally difficult to optimize it.
However, if you have mastered the theory, the ball problem can be promoted. For example, you can weigh up to 27 + 14 = 41 times for four times. The premise is that you have one more standard ball, so the first weighing is 14 vs 13 + 1. If it is equal, the bad ball will be in the remaining 14, it is converted to the 14-ball weighing problem described above. If not, then the bad balls are in 27. By reasonable allocation, you can certainly differentiate them into 9 in 3 groups, determine which 9 balls the Bad ball is in by one weighing. Because one weighing has three states, you can divide a pile of balls into three groups. Each of the following groups has one point. Therefore, the 3rd power of 27 = 3 indicates that three weighing times can be distinguished.
It is not hard to see that, if it is five times, a maximum of 27*3 + 41 = 122 pieces can be weighed. The following can be a series of analogy. Interested comrades can find its formula.
The last question is a question. Since we can have three components, why can we only weigh 14 instead of 27 for three times?