2014-03-20 01:02

题目:无力描述的一道智力题,真是货真价实的智力题,让我充分怀疑自己智力的智力题。有兴趣的还是看书去吧。

解法:能把题目看懂,你就完成80%了,用反证法吧。

代码:

 // 6.4 There is an island with a bunch of people living there.
// The strange thing is, any blue-eyed tourists must leave immediately when they find out they're blue-eyed.
// Everyone can see others' eye colors, but not their own.
// They know there'll be at least one blue-eyed tourists. If no more, the game ends.
// Answer:
// Suppose there're n people and c are blue-eyed.
// If n == 1, that one will soon find out nobody else is blue-eyed, he'll leave on the 1st day.
// If n == 2, those two will see one blue-eyed, they are not sure if c == 1 or c == 2.
// But on the second day, when they still see each other, they know c == 2. Otherwise the one would have left. They'll leave on the 2nd day.
// With mathematical induction, it can be proven that all the c blue-eyed will leave on the cth day together.
// The most difficult part for me, is that when they can't be sure, they will simply stay. I thought every day there must've been someone leaving.
int main()
{
return ;
}

《Cracking the Coding Interview》——第6章:智力题——题目4的更多相关文章

  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(CC150第五版)

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

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

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

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

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

随机推荐

  1. 笨办法学Python(零)

    py走起!!! 习题0:准备工作 Windows平台 1. 用浏览器打开 http://learnpythonthehardway.org/exercise0.html 下载并安装 gedit 文本编 ...

  2. Javascript打印金字塔,倒立金字塔,空心金字塔,菱形,空心菱形等

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. node实现爬虫

    node实现获取到豆瓣电影排行榜页面. 准备工作: 1.新建一个文件夹node 在当前文件夹中打开cmd 下载 npm install 初始化 npm init(注意一下:如果你的npm init没有 ...

  4. Nagios监控ActiveMQ插件开发和部署注意事项

    前提,监控服务器是Ubuntu14 操作系统.被监控服务器是RHEL6.5 RHEL7 1.自定义插件可以使用bash.python等脚本来实现. 2.通过nrpe插件来实现监控服务器和被监控主机之间 ...

  5. Last_SQL_Errno: 1050

    主库上create table,从库上存在. 报错信息如下所示:                Last_SQL_Errno: 1050                Last_SQL_Error: ...

  6. js实现弹窗一个ip在24小时只弹出一次的代码

    function cookieGO(name) { var today = new Date(); var expires = new Date(); expires.setTime(today.ge ...

  7. 第33章 TIM—电容按键检测—零死角玩转STM32-F429系列

    第33章     TIM—电容按键检测 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fir ...

  8. Python2.x 和 3.x 的区别

    Python有两个版本,2.x 和 3.x ,两个版本不兼容,3.x 不不考虑对2.x代码的向后兼容. 在3.x中,一些语法,内建函数和对象的行为都有所调整. 大部分的python库都支持 pytho ...

  9. C#程序设计入门经典之C#的基本语法

    C#代码的外观和操作方式与C++和Java非常类似.初看起来,其语法可能比较混乱,不像书面英语和其他语言.但是,在C#编程中,使用的样式是比较清晰的,不用花太多的力气就可以编写出可读性很强的代码. 与 ...

  10. C编程经验总结

    Turbo c Return (z);=return z; 图形界面的有scanf(“%d ~%d\n”,&~,&~);注意:中间不能有乱的东西 Printf(“~~~ %d~~%d\ ...