12 balls. the only method for finding a ball of different quality three times in Tianping.

Source: Internet
Author: User
You can see one method on the Internet:

In three groups: A1, A2, A3, A4; B1, B2, B3, B4; C1, C2, C3, C4;

Switch (comparison (a1a2a3a4, b1b2b3b4) // The first comparison
{
Case =:
Swicth (comparison (C1, C2) // second comparison
{
Case>:
If (C1> C3) return C1 (heavier); // The third comparison
Else if (C1 = C3) return C2 (lighter );
// C1 <C3 is not possible
Break;
Case <:
If (C1 <C3) return C1 (lighter); // The third comparison
Else if (C1 = C3) return C2 (heavier );
// C1> C3 is not possible
Break;
Case =:
If (C1 = C3) return C4; // The third comparison
Else if (C1> C3) return C3 (lighter );
Else if (C1 <C3) return C3 (heavier );
Break;

}
Break;
Case>:/* This indicates that c1c2c3c4 is normal */
Switch (comparison (a1c2c3c4, b1a2a3a4) // second comparison
{
Case>:/* description in A1 and B1 */
If (a1b1> c1c2) return A1 (heavy); // The third comparison
Else if (a1b1 <c1c2) return B1 (light );
// A1b1 = c1c2 is not possible
Break;
Case <:/* indicates that the request is in A2, A3, and A4, and is heavier */
If (A3> A2) return A3 (heavy); // The third comparison
Else if (A3 <A2) return A2 (heavy );
Else if (A3 = a2) return A4 (heavy );
Break;
Case =:/* indicates that the request is in B2, B3, B4, and is lighter */
If (B3> B2) return B2 (light); // The third comparison

Else if (B3 <B2) return B3 (light );
Else if (B3 = b2) return B4 (light );
Break;
}

Break;
Case <:
The operation can be inferred by> symmetry.

Break;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.