Questions like this:
There are eight coins, one of which is fake, and the amount is measured on the balance. I don't know whether the fake is really heavy or light. Could you tell me how many times it will take to determine whether it is false, severity (5 points ). Use C code (25 points ).
First, determine the number of times
8 balls * 2 status = 16
Balance 3 (left and right)
Known 3 ^ 2 <16 <3 ^ 3
So it can be called at least three times.
Then, find out the bad one. The simplest method is to determine whether it is light or heavy, and then locate it by 3 points. however, there is a problem here, and there is no way to determine whether the problem is light or heavy without the benchmark value. you can only move this step to the next step.
Construct two ing tables
First measurement [012] [345]
Second measurement [036] [147]
If the problematic one is heavy, the problematic ID can be obtained based on the two detection results.
| |
Left |
Right |
Ping |
| Left |
0 |
1 |
2 |
| Right |
3 |
4 |
5 |
| Ping |
6 |
7 |
|
Similarly, if there is a problem, it is light.
| |
Left |
Right |
Ping |
| Left |
4 |
3 |
5 |
| Right |
1 |
0 |
2 |
| Ping |
7 |
6 |
|
Then it's easy to merge two tables. In this way, we can find two coins, one of which is bad, and the other six are normal.
For the third time, check whether one of the coins is equal to a normal coin,
So we can find out.
Coin find_bad_coin (COIN coins [8]) {int tab [3] [3] ={{, 25 },{, 52 },{,-1 }}; // test () = 0 left weight, test () = 1 right weight, test () = 2 flat int T1 = test (Coins [0] + coins [1] + coins [2], coins [3] + coins [4] + coins [5]); int t2 = test (Coins [0] + coins [3] + coins [6], coins [1] + coins [4] + coins [7]); int res = tab [T1] [T2]; // obtain a normal coin int cc = t1 = 2? 0: 6; If (test (Coins [res % 10], coins [CC]) = 2) return coins [Res/10]; else return coins [res % 10];}