There are 12 balls, one of which has a weight different from the other 11 balls. The weights of the other 11 balls are the same. The condition is that there is only one balance. The balance must be weighed three times and the ball is retrieved.
If (ABCD = 1234) {// The First Time
// The target is in ABCD.
If (ABC = ABC) {// ABC is the second standard ball...
// Target d
If (D> 1) {// the third time
Bad ball is D, heavy;
} Else {
Bad ball is D, light;
}
} Elseif (ABC> ABC) {// ABC is the second standard ball...
// The target is in ABC and the Bad ball is heavy.
If (AA = bb) {// The third time ......
The Bad ball is C and heavy;
} Elseif (AA> BB) {// The third time ......
Bad ball is a, heavy;
} Else {// The third time ......
Bad ball is B, heavy
}
} Else {// ABC is the second standard ball...
// The target is in ABC and the Bad ball is heavy.
// Same as the preceding solution, the third time ......
}
} Elseif (ABCD> 1234) {// for the first time... then ABCD is standard
// The target is in abcd1234 and 234 is removed.
If (AABC = 1bcd) {// the second time...
// The target is in 234... light ..
// The third time... the solution is the same as above...
} Elseif (AABC <1bcd ){
// The target is in BCD...
// The third time... the solution is the same as above...
} Else {
// In the target a or 1... 1 is light, and a is heavy.
}
} Else {// The first time... ABCD <1234
// The target is in abcd1234 and the BCD is removed.
If (a234> 1abc ){//.....
// The target value is 234 ..
} Elseif (a234 <1abc ){
// When the target is a or 1... A, it is light... 1, it is heavy ..
} Else {
// Target in BCD... light ..
// The third time... the solution is the same as above...
}
}