Careercup - Microsoft面试题 - 5428361417457664
2014-05-11 03:37
原题:
You have three jars filled with candies. One jar is filled with banana candies, one jar is filled with lemon candies and one jar has a mix of both. All the jars are mislabelled (i.e. all the jars have wrong labels about what kind of candies they contain).
All the candies look very similar in shape, size and color and they even smell the same. The only way to distinguish them is by tasting.
You have to eat one and only one candy to determine the correct jar labels. You can eat that one candy from any jar you want as long as you eat only one in total.
题目:有三罐子糖,其中一罐香蕉糖、一罐柠檬糖、一罐是两者混合。每个管子上贴的标签都是错的。如果允许你选一罐拿出一颗糖吃掉,能否辨认出所有罐子实际装了什么糖?
解法:只能吃一颗糖,根据对称性原则,吃香蕉或者柠檬是等效的,所以肯定吃混合的那一罐。因为标签全是错的,所以吃出来是什么糖,那一罐就是什么糖。接下来顺着推出其他两罐糖就可以了。排除法是个好东西。
代码:
// http://www.careercup.com/question?id=5428361417457664
Answer:
All three baskets are wrongly labeled, thus the "mixed" one is either apple or orange.
If the "mixed" basket is orange, the "apple" basket can't be orange, it must mixed. The "orange" must be apple.
mixed -> orange
orange -> apple
apple -> mixed
If the "mixed" basket is apple, the "orange" basket can't be apple, it must mixed. The "apple" must be orange.
mixed -> apple
orange -> mixed
apple -> orange
Careercup - Microsoft面试题 - 5428361417457664的更多相关文章
- Careercup - Microsoft面试题 - 6314866323226624
2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...
- Careercup - Microsoft面试题 - 6366101810184192
2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...
- Careercup - Microsoft面试题 - 24308662
2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...
- Careercup - Microsoft面试题 - 5700293077499904
2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...
- Careercup - Microsoft面试题 - 5204967652589568
2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...
- Careercup - Microsoft面试题 - 5175246478901248
2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...
- Careercup - Microsoft面试题 - 5718181884723200
2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...
- Careercup - Microsoft面试题 - 5173689888800768
2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...
- Careercup - Microsoft面试题 - 6282862240202752
2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...
随机推荐
- 华为OJ-合唱队
华为OJ-初级题-合唱队 思路与分析 本题可以用DP的方法,分别从正向和逆向的两个方向求,该数组即186 186 150 200 160 130 197 200的上升对大序列.正向为[1, 1, 1, ...
- 设置field的背景颜色以及对stylesheet的理解
今天遇到一个需求:在做页面输入验证的时候,如果用户没有输入某个项,那么这个项显示为红色,一直没头绪,也找peoplebook,发现field有一个style的方法,后来又在谷歌上找,终于找到了方法: ...
- 各种数据处理方案(SQL,NoSQL,其他)的应用场景
综合stackoverflow和linkin上的相关讨论,还有我个人的工作经验: Redis应用场景(大部分场景下memcache可以用Redis代替,所以不单独讨论) 线上业务,读写的高性能要求 ...
- mac 下 svn ignore 操作
如何在svn中设备忽略的文件或者文件夹 1.如果你还没有对你的文件夹进行版本控制,则可以直接图形操作上进行ignore,或者在命令中运行 svn propedit svn:ignore 文件夹名 . ...
- 用过的一些js函数[备份用的]
1.类似php的htmlspecialchars函数,如需要可以自行增加其它代替 function _htmlspecialchars(str) { str = str.replace(/&/ ...
- FileInputStream利用缓冲数组读取数据
package cd.itcast.fileinputstream; import java.io.File; import java.io.FileInputStream; import java. ...
- 可以获取get post url 传递参数的统一方法
public static string objRequest(string requestName) { object obj = HttpContext.Current.Request[reque ...
- Ubuntu 下安装 Oracle JDK
sudo add-apt-repository ppa:webupd8team/javasudo apt-get updatesudo apt-get install oracle-java8-ins ...
- JS中的集中页面跳转的方法
第一种: <script language="javascript" type="text/javascript"> wi ...
- GPS之NMEA协议20160526
NMEA 0183是美国国家海洋电子协会(National Marine Electronics Association)为海用电子设备制定的标准格式.现在已经成为GPS导航设备统一的RTCM(Rad ...