砸蛋问题

 2 Egg Problem

* You are given 2 eggs.

* You have access to a 100-storey building.

* Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100th floor. Both eggs are identical.

* You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking.

Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process

100层楼,2个鸡蛋。某层之上扔鸡蛋就会碎。问至少要测试多少次才能试出这个层数。

答:

p1. 如果只有1个鸡蛋,那我们只能从一楼开始一层一层的测,否则砸烂了就没得测了。

现在有2个鸡蛋,有个鸡蛋可以浪费了,用一号鸡蛋来缩小范围,二号鸡蛋在一号鸡蛋缩小的范围内一层一层的测试。

比如一号鸡蛋每十层扔一下,10,20,30...... 如果在30层碎了,二号鸡蛋可以从21层开始测试。

 

现在的问题是如何确定一号鸡蛋每多少层测试一下,才能平衡1号2号鸡蛋的测试次数,使之最小。

设x层测试一下,最坏情况下需要测试

n =100/x+x  >=2(100/x *x) ^ (1/2)

n>=20

为了使得n最小 x = 100^(1/2) = 10

 

扩展: 3个鸡蛋的情况

设一号鸡蛋x层测试一下,总次数

100/x+x^(1/2)

可得 x=22 最小

 

 

(数学忘的差不多了,不完整,有空再补充)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值