随笔- 509  文章- 0  评论- 151  阅读- 22万 

2014-03-20 01:08

题目:扔鸡蛋问题。有一个鸡蛋,如果从N楼扔下去恰好会摔碎,低于N楼则不碎,可以继续扔。给你两个这样的鸡蛋,要求你一定得求出N,怎么扔才能减少最坏情况下的扔的次数?

解法:为了让worst case得到最优化,就需要让best case和worst case最接近。具体做法请参见书上题解,因为我一直在想着二分,实在是摸不着头脑。

代码:

复制代码
 1 // 6.5 Given 100 floors and 2 eggs.
 2 // If the egg can sustain a dropping from nth floor, and will break for higher drop, please find a way to determine n, and minimize the number of droppings.
 3 // Answer:
 4 //    That's indeed a brain teaser with mathematical principle.
 5 //    It just doesn't make sense to me, why it is optimized when num_of_drop(egg1) + num_of_drop(egg2) always stays the same.
 6 // Perhaps you should read the book yourself. I do hope that I don't face such a question. Quite a teaser, tease me more.
 7 int main()
 8 {
 9     return 0;
10 }
复制代码

 

 posted on   zhuli19901106  阅读(207)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示