[CareerCup] 6.4 Blue Eyes People on Island 岛上的蓝眼人
6.4 A bunch of people are living on an island, when a visitor comes with a strange order: all blue-eyed people must leave the island as soon as possible. There will be a flight out at 8:00pm every evening. Each person can see everyone else's eye color, but they do not know their own (nor is anyone allowed to tell them). Additionally, they do not know how many people have blue eyes, although they do know that at least one person does. How many days will it take the blue-eyed people to leave?
这道题假定一个岛上有很多人,其中有些人是蓝眼睛的,设定是蓝眼睛的人要尽可能早的离开岛,每天晚上八点都有飞机离开岛。每个人可以看见别人眼睛的颜色,但是不知道自己眼睛的颜色,而且也不能被告知,问需要多少天可以让蓝眼睛人都离开。
这道题让我想起来了很小时候听过的一道智力题,是小猴带帽的问题,说是有四个帽子,三个蓝色一个红色的,有三只小猴一人戴其中一个帽子,每只小猴不知道自己戴的什么颜色的帽子,但能看到其他小猴戴的帽子的颜色。其中一只小猴看到其他两只小猴都是蓝色的帽子,它就在考虑自己的到底是红色的还是蓝色的,当它发现大家都陷入了沉思时,它马上说自己戴的是蓝色的,请问问什么?我小时候想了很久都不明白,其实很简单,如果这小猴戴的是红色的帽子,那么其他小猴马上就知道自己戴的是蓝色的,因为只有一顶红色的帽子,既然其他小猴也不知道,那么自己戴的肯定是蓝色的。
这道题的思路和上面的小猴戴帽有些类似,我们先从简单的开始分析,假设岛上有c个人是蓝眼睛:
1. c = 1, 这种情况最简单,应为那个人看到周围都没有蓝眼睛,由于题目设定了一定有蓝眼睛,那么自己肯定是,所以当晚就可以坐飞机离开。
2. c = 2,这时候蓝眼睛的人可以看到周围有一个人是蓝眼睛,那么他可以推断岛上只有1个或2个蓝眼睛人,如果那人第一晚,没走,他就可以推断出自己也是蓝眼睛,于是两个蓝眼睛的人第二晚同时走了。
3. c = 3,和上面类似,蓝眼睛的人可以看到周围有两个蓝眼睛,则推断岛上有2个或3个蓝眼睛人,如果只有两个蓝眼睛,那么他两第二天晚上就会同时离开,如果第二晚没有离开,则说明自己也是蓝眼睛,则三人第三晚上同时离开。
4. c = c, 推广到c个人,根据如上分析,c个蓝眼睛的人会等到第c天晚上,所有c个蓝眼睛的人同时离开。
[CareerCup] 6.4 Blue Eyes People on Island 岛上的蓝眼人的更多相关文章
- CareerCup All in One 题目汇总 (未完待续...)
Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...
- CareerCup All in One 题目汇总
Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...
- Blue Star(日剧:今夜 可否拥你入怀歌词)
BLUE STAR-COLOR CREATION Oh I Know I need you in my life ひさしぶりの 译:时隔许久的 やわらかなかせがふきぬける 清风温柔吹拂 むねのおくの ...
- Fishnet(暴力POJ 1408)
Fishnet Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1911 Accepted: 1227 Descripti ...
- Fishnet(计算几何)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1642 Accepted: 1051 Description A fis ...
- POJ 1408 Fishnet【枚举+线段相交+叉积求面积】
题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- 蓝眼睛与红眼睛(The blue-eyed islanders puzzle)
澳大利亚的华裔数学神童陶哲轩曾在网上贴出来一个问题 The blue-eyed islanders puzzle 让大家思考,逗大家玩儿. 说一个岛上有100个人,其中有5个红眼睛,95个蓝眼睛.这个 ...
- POJ 1408:Fishnet
Fishnet Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1921 Accepted: 1234 Descripti ...
- CSS3与页面布局学习总结(七)——前端预处理技术(Less、Sass、CoffeeScript、TypeScript)
CSS不像其它高级语言一样支持算术运算.变量.流程控制与面向对象特性,所以CSS样式较多时会引起一些问题,如修改复杂,冗余,某些别的语言很简单的功能实现不了等.而javascript则是一种半面向对象 ...
随机推荐
- Linux网络编程&内核学习
c语言: 基础篇 1.<写给大家看的C语言书(第2版)> 原书名: Absolute Beginner's Guide to C (2nd Edition) 原出版社: Sams 作者: ...
- Autocomplete:属性介绍、firefox中文支持问题
如有问题,请前往 http://www.cnblogs.com/dreamowneryong/p/4953911.html 原文评论交流 一,属性介绍 * minChars (Number) 在触发a ...
- 【故障处理】CRS-1153错误处理
[故障处理]CRS-1153错误处理 1 CRS-1153: There was an error setting Oracle Clusterware to rolling patch mode. ...
- ASP.NET发布网站遇到的几个问题
环境背景 操作系统:Win7 开发工具:Visual Studio 2013 Framework: Framework 4.0 Issue1: 无法识别的属性“targetFramework” 解决方 ...
- c# App.Config详解
c# App.Config详解 应用程序配置文件是标准的 XML 文件,XML 标记和属性是区分大小写的.它是可以按需要更改的,开发人员可以使用配置文件来更改设置,而不必重编译应用程序. 配置文件的根 ...
- Hadoop step by step _ install and configuration environment
1.安装centos linux系统. 2.配置静态IP 3.配置防火墙 4.添加hadoop用户 5.检查并安装jdk 配置环境变量 6.配置sshd服务 7.配置ssh免密码登录 8.格式化nam ...
- gre网络细节
一.OpenStack网络设备的命名规律: 1.TenantA的router和Linux网络命名空间qrouter名称 root@controller:~# neutron --os-tenant-n ...
- LeetCode题解-----First Missing Positive
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- TDD in Expert Python Programmin
Test-Driven Development PrinciplesTDD consists of writing test cases that cover a desired feature, t ...
- 基础KMP两道
1. HDU 1711 Number Sequence 代码: #include <iostream> #include <cstdio> #include <cstri ...