二进制的有趣玩法
二进制的有趣玩法
利用二进制解决问题
有100瓶药,1瓶有毒,现在有7只老鼠,现在让你用1天时间找出拿一瓶有毒,老鼠喝完药,不会立马死,第二天才死。请问你怎么做?
解答
2**7=128,---》2**6 = 64 这里为什么要7只老鼠,6只太少,8太多,2**7正好满足
100瓶,编号1-100 10
7个老鼠,
a, b, c, d, e, f, g
1 0 0 0 0 0 0 1 g老鼠喝
2 0 0 0 0 0 1 0 f老鼠喝
3 0 0 0 0 0 1 1 fg老鼠喝
4 0 0 0 0 1 0 0 e老鼠喝
5 0 0 0 0 1 0 1 e和g老鼠喝
...
10 0 0 0 1 0 1 0 d和f老鼠喝
比如其他老鼠没事,f,g老鼠第二天死了说明第3瓶药有毒
Only you can control your future
You're not alone. You still have family,peopel who care for you and want to save you.