《Cracking the Coding Interview》——第6章:智力题——题目5
2014-03-20 01:08
题目:扔鸡蛋问题。有一个鸡蛋,如果从N楼扔下去恰好会摔碎,低于N楼则不碎,可以继续扔。给你两个这样的鸡蛋,要求你一定得求出N,怎么扔才能减少最坏情况下的扔的次数?
解法:为了让worst case得到最优化,就需要让best case和worst case最接近。具体做法请参见书上题解,因为我一直在想着二分,实在是摸不着头脑。
代码:
// 6.5 Given 100 floors and 2 eggs.
// 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.
// Answer:
// That's indeed a brain teaser with mathematical principle.
// 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.
// Perhaps you should read the book yourself. I do hope that I don't face such a question. Quite a teaser, tease me more.
int main()
{
return ;
}
《Cracking the Coding Interview》——第6章:智力题——题目5的更多相关文章
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- Cracking the Coding Interview(Stacks and Queues)
Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...
- 《Cracking the Coding Interview》——第6章:智力题——题目4
2014-03-20 01:02 题目:无力描述的一道智力题,真是货真价实的智力题,让我充分怀疑自己智力的智力题.有兴趣的还是看书去吧. 解法:能把题目看懂,你就完成80%了,用反证法吧. 代码: / ...
- 二刷Cracking the Coding Interview(CC150第五版)
第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...
- 《Cracking the Coding Interview》——第6章:智力题——题目6
2014-03-20 01:14 题目:有100栈灯,一开始都关着.如果你按照n从1~100的顺序,每次都掰一下n的倍数的开关(开->关,关->开),那么到最后有多少灯是亮的? 解法:这个 ...
随机推荐
- 笨办法学Python(二十五)
习题 25: 更多更多的练习 我们将做一些关于函数和变量的练习,以确认你真正掌握了这些知识.这节练习对你来说可以说是一本道:写程序,逐行研究,弄懂它. 不过这节练习还是有些不同,你不需要运行它,取而代 ...
- phpStudy:使用localhost无法访问的解决方案
今天遇到新的问题,很有意思,当使用Localhost时,发现报403错误: 百度找到问题所在:没有权限问题 所以我们打开phpStudy,找到配置文件“vhosts-conf”,看到的情况是这样的 接 ...
- Torch.no_grad()影响MSE损失
相关描述 https://discuss.pytorch.org/t/torch-no-grad-affecting-outputs-loss/28595/3 今天在训练网络的时候,发现mseloss ...
- CentOS 6\7修改主机名
1.CentOS6修改主机名 1)临时修改主机名: 显示主机名: oracle@localhost:~$ hostname localhost 修改 oracle@localhost:~$ sudo ...
- Centos下Yum安装PHP5.5,5.6
默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案: 1.检查当前安装的PHP包 yum list installed | grep php 如果有安装的PHP包,先删除他们 ...
- office2010
MS office2010 360网盘:http://yunpan.cn/QajXaRWbnpTzF (提取码:cf72) 如何激活参见我下面的博客: http://www.cnblogs.com/l ...
- Strut2 的 Action获取JSP 页面参数的方法
struts2 Action获取表单传值1.通过属性驱动式JSP:<form action="sys/login.action" method="post" ...
- 一些简单的Js代码的封装
1 function getById(id) { 2 3 } 4 5 function getAttr(el, k) { 6 7 } 8 9 function setAttr(el, k, v) { ...
- 优化tableView性能(针对滑动时出现卡的现象)
优化tableView性能(针对滑动时出现卡的现象) 在iOS应用中,UITableView应该是使用率最高的视图之一了.iPod.时钟.日历.备忘录.Mail.天气.照片.电话.短信. Safari ...
- mysql架构和历史
存储引擎 查看: show table status like 'bigcourse'; 结果: +-----------+--------+---------+------------+------ ...