《Cracking the Coding Interview》——第6章:智力题——题目4
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的更多相关文章
- 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(CC150第五版)
第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...
- 《Cracking the Coding Interview》——第6章:智力题——题目6
2014-03-20 01:14 题目:有100栈灯,一开始都关着.如果你按照n从1~100的顺序,每次都掰一下n的倍数的开关(开->关,关->开),那么到最后有多少灯是亮的? 解法:这个 ...
- 《Cracking the Coding Interview》——第6章:智力题——题目5
2014-03-20 01:08 题目:扔鸡蛋问题.有一个鸡蛋,如果从N楼扔下去恰好会摔碎,低于N楼则不碎,可以继续扔.给你两个这样的鸡蛋,要求你一定得求出N,怎么扔才能减少最坏情况下的扔的次数? 解 ...
随机推荐
- Simotion应用案例,使用Simotion web server调试,使用Project Generator创建项目,Simosim模拟运行运行项目
Simotion web server simotion项目设计和调试过程中,web server功能越来越常用.例如Project generator生成的FBAxis, winder, print ...
- pat甲级1085
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- C语言中的特殊变量
auto: 函数中的局部变量,动态地分配存储空间,数据存储在动态存储区中,在调用该函数时系统会给它们分配存储空间,在函数调用结束时就自动释放这些存储空间. register: 为了提高效率,C语言允许 ...
- Android(java)学习笔记72:ProgressBar的使用
1. ProgressBar使用 首先我们看例程如下: (1) main.xml文件如下: <?xml version="1.0" encoding="utf-8& ...
- Poj(2560),最小生成树,Prim
题目链接:http://poj.org/problem?id=2560 只想说“全都是套路”,关键建图. #include <stdio.h> #include <string.h& ...
- Zabbix3.0部署实践
Zabbix3.0部署实践 Zabbix3整个web界面做了一个全新的设计. 1.1Zabbix环境准备 [root@linux-node1 ~]# cat /etc/redhat-release ...
- PHP设计模式练习——制作简单的投诉页面
---恢复内容开始--- <?php /* * 设计模式练习 * 1.数据库连接类(单例模式) * 2.调用接口实现留言本功能(工厂模式) * 3.实现分级举报处理功能(责任链模式) * 4.发 ...
- 2018年第九届蓝桥杯【C++省赛B组】第二题 明码
汉字的字形存在于字库中,即便在今天,16点阵的字库也仍然使用广泛.16点阵的字库把每个汉字看成是16x16个像素信息.并把这些信息记录在字节中. 一个字节可以存储8位信息,用32个字节就可以存一个汉字 ...
- IIS配置MIME类型
有时候我们上传的视频,如果IIS上没有配置此格式是播放不了的.这个时候需要你在IIS上添加这个类型才能播放. MIME类型 ①打开你的IIS,点你的网站 ②双击 MIME类型 ③右键-->添加 ...
- base_lr, blobs_lr
caffe里面,原来以为是不可以随便调整学习率的,现在看来是可以的.base_lr是适用于所有层的学习率,而针对单个层,可以通过增加两个blobs_lr,用来调整该层的学习率,为什么是两个呢,因为一个 ...