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.

题目:有三罐子糖,其中一罐香蕉糖、一罐柠檬糖、一罐是两者混合。每个管子上贴的标签都是错的。如果允许你选一罐拿出一颗糖吃掉,能否辨认出所有罐子实际装了什么糖?

解法:只能吃一颗糖,根据对称性原则,吃香蕉或者柠檬是等效的,所以肯定吃混合的那一罐。因为标签全是错的,所以吃出来是什么糖,那一罐就是什么糖。接下来顺着推出其他两罐糖就可以了。排除法是个好东西。

代码:

 1 // http://www.careercup.com/question?id=5428361417457664
 2 Answer:
 3     All three baskets are wrongly labeled, thus the "mixed" one is either apple or orange.
 4     If the "mixed" basket is orange, the "apple" basket can't be orange, it must mixed. The "orange" must be apple.
 5         mixed -> orange
 6         orange -> apple
 7         apple -> mixed
 8     If the "mixed" basket is apple, the "orange" basket can't be apple, it must mixed. The "apple" must be orange.
 9         mixed -> apple
10         orange -> mixed
11         apple -> orange
12         

转载于:https://www.cnblogs.com/zhuli19901106/p/3721319.html

Careercup - Microsoft面试题 - 5428361417457664相关推荐

  1. Careercup - Microsoft面试题 - 5752271719628800

    2014-05-10 20:31 题目链接 原题: Given an array of integers and a length L, find a sub-array of length L su ...

  2. Careercup - Microsoft面试题 - 5672369481842688

    2014-05-12 06:27 题目链接 原题: Find the max height of a binary tree. 题目:计算二叉树的最大高度. 解法:最大高度?高度不就是最深的叶子节点到 ...

  3. Careercup - Google面试题 - 4699414551592960

    2014-05-06 13:34 题目链接 原题: we have a random list of people. each person knows his own height and the ...

  4. Careercup - Google面试题 - 5424071030341632

    2014-05-08 22:55 题目链接 原题: Given a list of strings. Produce a list of the longest common suffixes. If ...

  5. Careercup - Google面试题 - 5377673471721472

    2014-05-08 22:42 题目链接 原题: How would you split a search query across multiple machines? 题目:如何把一个搜索que ...

  6. Careercup - Google面试题 - 4877486110277632

    2014-05-08 05:16 题目链接 原题: Given a circle with N defined points and a point M outside the circle, fin ...

  7. python可以不用主函数吗_python自定义函数可以向前引用不用声明

    Careercup - Microsoft面试题 - 6543214668414976 2014-05-11 02:56 题目链接 原题: Write a function called FooBar ...

  8. origin和python有什么不同_python爬虫之git的使用(origin说明)

    1.首先我们回忆两个命令 #git remote add origin 远程仓库链接 #git push -u origin master 我们一起看看这个命令,git是git的一级命令,push就是 ...

  9. 计算机办公软件应用三套题目,办公软件应用试题中级汇编第3套

    办公软件应用中级Microsoft Office2010试题汇编 办公软件应用中级Microsoft Office2010试题汇编 (第03套) 第1单元:操作系统应用 (1) 第2单元:文字录入与编 ...

最新文章

  1. 奉劝程序员们:写再多代码,还不如提升这两大能力有价值!
  2. HDU 5459 Jesus Is Here (递推,组合数学)
  3. 后缀自动机序列自动机综合
  4. mysql主从授权_MySQL主从复制(10)读写分离授权多种方案
  5. 带有Spring Security的OAuth 2.0快速指南
  6. MySQL 数据库修改登录密码
  7. JavaScript对象中的this属性
  8. BASE64Encoder及BASE64Decoder的正确用法
  9. Noip2016day2
  10. JS内存泄漏实例解析
  11. 数据结构与算法 —— 向量的扩容策略与分摊时间复杂度
  12. 整合X-Admin前端框架改造ABP
  13. 《从0开始做运营[张亮]》——读书笔记
  14. 暑期实习-京东广告架构组三面面经
  15. 中小型局域网上网管理组网方案
  16. 台式计算机红外线端口,台式电脑的红外线端口在哪?
  17. classes是什么意思怎么读_class是什么意思_class怎么读_class翻译_用法_发音_词组_同反义词_班-新东方在线英语词典...
  18. sp许可证有什么用呢?
  19. Ngrok 实现内网穿透教程(Ngrok 和 Sunny-Ngrok )
  20. 官宣!CSDN“2019 优秀 AI、IoT 应用案例 TOP 30+”重磅发布!

热门文章

  1. Python的特殊成员
  2. 正则表达式之反向引用
  3. Quartz简单实例
  4. 单片机的 FIFO循环队列实现
  5. springboot webservice cxf 客户端调用
  6. JS最新的身份证验证代码
  7. Android 数据解析——Gson与json
  8. Android 启动白屏,简单解决方法
  9. mpvue 从零开始 女友的衣装 1 pages
  10. 13新功能_再聊聊灵感盒 -Marginnote 3.6.12/13新功能