测试策略

问题:
有一个100层高的大厦,你手中有两个相同的玻璃围棋子。从这个大厦的某一层扔下围棋子就会碎,用你手中的这两个玻璃围棋子,找出一个最优的策略,来得知那个临界层面.

参考答案:

One drop allows us to test 1 floor.

Two drops can test 3 floors: Test the second floor first. If it breaks, test the first floor with the other ball. If not, test the top floor with either ball.

Three drops can test 6 floors: Test the third floor first. If it breaks, test the bottom 2 floors in order with the other ball. If not, test the top 3 floors as described above.

Four drops can test 10 floors: Test the fourth floor first. If it breaks, test the bottom 3 floors in order with the other ball. If not, test the top 6 floors as described above.

N drops allows you to test the number of floors equal to the sum of 1 to n. Fourteen drops can test 105 floors: Test the fourteenth floor first. If it breaks, test the bottom 13 floors in order with the other ball. If not, test the twenty-seventh floor next (14 3), and so on.

For any given drop, the number of drops you’ll need after that should be the same if that ball breaks or not (or sometimes they are off by 1 if your total is not an even sum-of-1-to-n).

The optimum test protocol for 100 floors, then, requires a maximum of 14 drops. The next step is to derive a testing strategy that divides the 100 floors using the series 14+13+12+11+10+9+8+7+6+5+4+3+2+1.

The best testing strategy starts with a drop from floor 14; then a drop from floor 27 (14+13); then 39 (14+13+12);etc. The full pattern is 14, 27, 39, 50, 60, 69, 77, 84, 90, 95, 99, 100.

In practice, this series sacrifices the first ball to point to an everdecreasing series of possible target floors. A small number of drops using the second ball then identifies the target floor. Simply go back to the previously tested floor and start working up a floor at a time.
Eventually,you will determine the floor at which the bowling ball shatters.

This is the most efficient testing algorithm.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值