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的更多相关文章

  1. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  2. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  3. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  4. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  5. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  6. 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 ...

  7. 《Cracking the Coding Interview》——第6章:智力题——题目4

    2014-03-20 01:02 题目:无力描述的一道智力题,真是货真价实的智力题,让我充分怀疑自己智力的智力题.有兴趣的还是看书去吧. 解法:能把题目看懂,你就完成80%了,用反证法吧. 代码: / ...

  8. 二刷Cracking the Coding Interview(CC150第五版)

    第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...

  9. 《Cracking the Coding Interview》——第6章:智力题——题目6

    2014-03-20 01:14 题目:有100栈灯,一开始都关着.如果你按照n从1~100的顺序,每次都掰一下n的倍数的开关(开->关,关->开),那么到最后有多少灯是亮的? 解法:这个 ...

随机推荐

  1. python从字符串中提取数字,使用正则表达式

    使用正则表达式 import re D = re.findall(r"\d+\.?\d*",line) print(D) -7.23246 10.8959 5.19534 0.06 ...

  2. ubuntu16.04安装中文输入法(转)

    转自: https://zhidao.baidu.com/question/619127469641961052.html ubuntu没有预装中文输入法,需要自己安装 sudo apt instal ...

  3. jmeter参数化读取数据进行多次运行

    jmeter参数化数据,可以使用csv,还可以使用数据库的方式 1.使用csv读取数据 在线程组中,配置原件中,选择csv data set config 1.本地创建了16个数据,存为test.tx ...

  4. 转:spring mvc返回json数据格式

    转:http://www.cnblogs.com/ssslinppp/p/4675495.html <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: ...

  5. 2017.10.3 JDBC访问数据库的建立过程

    1·JDBC访问数据库,其访问流程: (1)注册驱动 (2)建立连接(Connection) (3)创建数据库操作对象用于执行SQL语句 (4)执行语句 (5)处理执行结果 (6)释放资源 2·注册驱 ...

  6. 文本编辑器Vim技巧

    1.  导入文件内容  :r  文件名 2.  插入当前日期  :r  !date 3. :!which ls 4. :r !命令

  7. git fetch和push的区别

    获取fetch的用法 git-fetch用于从另一个reposoitory下载objects和refs. 命令格式为:git fetch … 其中表示远端的仓库路径.git remote add or ...

  8. IE问题——列表项图像

    等我们实现列表时,经常会遇到一种情况:需要为列表的每一项的前面添加一个列表项图像. 我们在查阅W3C时会发现,在CSS中已经为我们提供了实现方法——“list-style-type”,我们来看看它的实 ...

  9. SpringBoot中使用配置文件

    一般都是把xml配置文件转换为@Bean的模式,如果非要使用xml配置文件,方式如下: /** * 将配置文件引入springboot */ @Configuration @ImportResourc ...

  10. Java +安卓 定时任务

    1.android 自带闹钟定时任务 安卓闹钟可以配合广播来实现(不推荐),系统资源浪费,安卓系统在5.0以后的定时 任务貌似触发时间不准了,因为了为了省电. //获取系统闹钟 AlarmManage ...