Careercup - Microsoft面试题 - 5428361417457664
生活随笔
收集整理的這篇文章主要介紹了
Careercup - Microsoft面试题 - 5428361417457664
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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.題目:有三罐子糖,其中一罐香蕉糖、一罐檸檬糖、一罐是兩者混合。每個(gè)管子上貼的標(biāo)簽都是錯(cuò)的。如果允許你選一罐拿出一顆糖吃掉,能否辨認(rèn)出所有罐子實(shí)際裝了什么糖?
解法:只能吃一顆糖,根據(jù)對(duì)稱性原則,吃香蕉或者檸檬是等效的,所以肯定吃混合的那一罐。因?yàn)闃?biāo)簽全是錯(cuò)的,所以吃出來(lái)是什么糖,那一罐就是什么糖。接下來(lái)順著推出其他兩罐糖就可以了。排除法是個(gè)好東西。
代碼:
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?
轉(zhuǎn)載于:https://www.cnblogs.com/zhuli19901106/p/3721319.html
總結(jié)
以上是生活随笔為你收集整理的Careercup - Microsoft面试题 - 5428361417457664的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: uniapp的云购商城源码/java电商
- 下一篇: Vim的6种模式