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也可以。