Careercup - Microsoft面试题 - 5428361417457664
生活随笔
收集整理的這篇文章主要介紹了
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.題目:有三罐子糖,其中一罐香蕉糖、一罐檸檬糖、一罐是兩者混合。每個管子上貼的標簽都是錯的。如果允許你選一罐拿出一顆糖吃掉,能否辨認出所有罐子實際裝了什么糖?
解法:只能吃一顆糖,根據對稱性原則,吃香蕉或者檸檬是等效的,所以肯定吃混合的那一罐。因為標簽全是錯的,所以吃出來是什么糖,那一罐就是什么糖。接下來順著推出其他兩罐糖就可以了。排除法是個好東西。
代碼:
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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: uniapp的云购商城源码/java电商
- 下一篇: Vim的6种模式