问题:有12个球,其中于1个球与其他11个不等重,求通过天枰(无砝码)3次称出坏球。
某种解法:
1、将12个球分为a、b、c三组:
a: a1 a2 a3 a4
b: b1 b2 b3 b4
c: c1 c2 c3 c4
2、通过以下方法称(python伪代码)
if a1+a2+a3+a4 == b1+b2+b3+b4 : // x in c1 c2 c3 c4 if c1+c2 == a1+a2 : // x in c3 c4 if c3 == a3 : c4 is x else c3 != a3 : c3 is x elif c1+c2 != a1+a2 : // x in c1 c2 if c1 == a1 : c2 is x else c1 != a1 : c1 is x elif a1+a2+a3+a4 != b1+b2+b3+b4 : // x in a b // reset a = heavier ... if a1+a2+a3+b1+b2 == c1+c2+c3+c4+a4 : // x in b3 b4 if b3 == c1 : b4 is x else b3 != c1 : b3 is x elif a1+a2+a3+b1+b2 > c1+c2+c3+c4+a4 : // x in a1 a2 a3 if a1 == a2 : a3 is x else a1 < a2 : a2 is x else a1 > a2 : a1 is x elif a1+a2+a3+b1+b2 < c1+c2+c3+c4+a4 : // x in b1 b2 a4 if b1 == b2 : a4 is x else b1 > b2 : b2 is x else b1 < b2 : b1 is x