Problem description:
4-6 IC Testing
Professor Diogenes has n considered to be exactly the same IC. In principle, they can be tested with each other. Professor's test device can measure two pieces at a time. When two pieces of chips are placed in the device, each piece tests the other and reports its quality. A good chip can always report the quality of another chip, but the result of a bad chip is unreliable. In this way, the four possible results for each test are as follows:
A chip report B chip report conclusion
B is good. A is good. Both are good. or both are bad.
B is good. A is bad. At least one is bad.
B is bad. A is good. At least one is bad.
B is bad. A is bad. At least one is bad.
A) prove that if more than n/2 chips are bad, in this paired test method, using any strategy cannot determine which chip is good. Assuming that bad chips can be combined to cheat professors.
B) if there are more than n/2 chips, consider finding a good chip from N. It turns out that n/2 pairs of tests are enough to reduce the problem size to nearly half of the original.
C) if there are more than n/2 chips, it is good to prove that a good chip can be found by testing the slave (n) pair. Returns and answers the recursion of the number of expression tests.
Note: very large scale integrated.
Algorithm analysis:
A) compare any chip with all other chips by using the exhaustive method, because more chips than n/2 are bad, and the bad chips can be combined to cheat professors, the test result is unreliable and it cannot be determined whether the chip is good or bad.
B) hypothesis: the number of a good chip, the number of B bad chips, and the test result of Z is a good test pair, where the number of all chips is X, if all the chips are bad, the test pairs are Y and x + y = z.
The idea of a binary test:
1. Random pairs, then a total of 'n'/2' pairs are tested respectively.
2. according to the Problem description: if the test result is either good or bad, discard the pair. If the test result is good or bad, discard one of them at will, leave one (if n is an odd number, the other chip is not paired. If Z is an odd number, discard the chip. If Z is an even number (0 is also regarded as an even number), leave the chip ). After this operation, the number of good chips left must be greater than the number of bad chips. After ipvn/2 testing, the scale of the original problem was reduced by nearly half.
3. Repeat Step 1. When n <= 2, only good chips are left.
Proof:
The test results show that at least one of the two chips is bad. Discarding this pair ensures that the number of good chips in the remaining chips is greater than the number of bad chips.
The test results are all good, which may be good for all chips, but may be all bad. Discard one of them at will and leave one. Set the logarithm of the chip to X, and the logarithm of the Bad chip to y. Consider N:
If n is an even number, x> Y. Therefore, the number of good chips left behind is greater than the number of bad chips;
If n is an odd number, there is no matching chip. Consider Z:
If Z is an odd number, x> Y will discard the chip. In this case, the number of good chips is greater than the number of bad chips;
If Z is an even number, consider this chip:
If the chip is good, then x> = Y, leave the good chip, so that the number of good chips is greater than the number of bad chips;
If the chip is bad, x-y> = 2. Leave the bad chip, so that the number of good chips is greater than the number of bad chips.
To sum up, the number of good chips left must be greater than the number of bad chips.
C) use the operation method in B. The recursion formula is F (n) = f (n/2) + n/2. This recursion is in line with the third case in the main theorem, so a good chip can be found by testing the pair (n.