6.5

Topic: There is a building of 100 floors. If an egg drops from the Nth floor or above it will break. If it’s dropped from any floor below, it will not break. You’re given 2 eggs. Find N, while minimizing the number of drops for the worst case.

1) Regardless of where we drop Egg 1, Egg 2 must do a linear search between the “breaking floor” and the next highest non-breaking floor.

2) We should make Drops(Egg1)+Drops(Egg2) keep unchanged. Or there will be a worst case, and the number will increase. 要让蛋不管在哪一层破,丢两个蛋的和始终为常数

3) If Egg1 starts at n1, Drops(Egg1)+Drops(Egg2)=n1;

Next, Egg1 starts at n2, Drops(Egg1)+Drops(Egg2)=2+(n2-n1-1)=n2-n1+1=n1                  so n2=2n1-1     

Next, Egg1 starts at n3, Drops(Egg1)+Drops(Egg2)=3+(n3-n2-1)=n3-n2+2=n2-n1+1=n1   so n3=3n1-3

Next, Egg1 starts at n4, Drops(Egg1)+Drops(Egg2)=4+(n4-n3-1)=n4-n3+3=n3-n2+2         so  n4=4n1-6

通式:n(t)=n(t-1)-t+1+n1=t*n1-(1+2+..+t-1)=tn1-t(t-1)/2

      n(t)>=100 且n(t)>n(t-1),求n1.

最后变为:t*t-t(t-1)/2>=100;   so  t>=14

所以n1=14, n2=27, n3=39…..

只要14次就可以测出来到底是哪一层,当然想大于14也可以。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值