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的更多相关文章

  1. Careercup - Microsoft面试题 - 6314866323226624

    2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...

  2. Careercup - Microsoft面试题 - 6366101810184192

    2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...

  3. Careercup - Microsoft面试题 - 24308662

    2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...

  4. Careercup - Microsoft面试题 - 5700293077499904

    2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...

  5. Careercup - Microsoft面试题 - 5204967652589568

    2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...

  6. Careercup - Microsoft面试题 - 5175246478901248

    2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...

  7. Careercup - Microsoft面试题 - 5718181884723200

    2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...

  8. Careercup - Microsoft面试题 - 5173689888800768

    2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...

  9. Careercup - Microsoft面试题 - 6282862240202752

    2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...

随机推荐

  1. 三、第一个Struts2应用案例(编码步骤)

    第一个Struts2应用案例(编码步骤) 编写2个jsp hello.jsp <body>     <a href="${pageContext.request.conte ...

  2. 将base64格式的字符串生成文件

    using System; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(stri ...

  3. Mysql连接测试代码

    <?php $link=mysql_connect('localhost','root','htuidc'); if($link) echo "success"; ?>

  4. C++获取得到图片的坐标和rgb

    #include <iostream> #include <fstream> #include <string> #include <windows.h> ...

  5. HTTP首部及各状态码

    通用首部:客户端和服务器都可以使用的通用首部,比如Status Code: 请求首部:请求首部是请求报文特有的,它们为服务器提供了一些额外信息,例如Accept: */* 用来告知服务器客户端会接受与 ...

  6. java8新特性笔记

    1.forEach(),遍历数据结构中的元素,括号内可以带一个闭包的方法 2.双冒号用法:forEach(this::doSchedule),如果运行环境是闭包,java允许使用双冒号的写法来直接调用 ...

  7. ASP.NET MVC4学习笔记之Controller的激活

    一. 高层相关类说明 当路由系统根据请求Url收集路由信息后,下一步就要将路由信息传给Controller激活系统,Controller激活系统负责实现了IController接口的Controlle ...

  8. EditText 监听回车事件 避免2次触发

    // 侦听回车事件 EidtText txtSN = (EditText) findViewById(R.id.txtSN); txtSN.setOnEditorActionListener(new ...

  9. Fix: Compile project encounter undefined reference to“xxx”error

    Need to add all the new cpp files to jni/Andriod.mk folder:

  10. c语言内存分配-malloc

    malloc 原型:(原来返回类型是char) extern void *malloc(unsigned int num_bytes); 头文件: #include <stdlib.h> ...