博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Careercup - Microsoft面试题 - 5428361417457664
阅读量:5128 次
发布时间:2019-06-13

本文共 1366 字,大约阅读时间需要 4 分钟。

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 -> apple10         orange -> mixed11         apple -> orange12

 

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

你可能感兴趣的文章
局域网内手机访问电脑网站注意几点
查看>>
[Serializable]的应用--注册码的生成,加密和验证
查看>>
Linux操作系统 和 Windows操作系统 的区别
查看>>
Android-多线程AsyncTask
查看>>
LeetCode【709. 转换成小写字母】
查看>>
如何在Access2007中使用日期类型查询数据
查看>>
CF992E Nastya and King-Shamans(线段树二分+思维)
查看>>
如果没有按照正常的先装iis后装.net的顺序,可以使用此命令重新注册一下:
查看>>
linux install ftp server
查看>>
Ubuntu下的eclipse安装subclipse遇到没有javahl的问题...(2天解决了)
查看>>
alter database databasename set single_user with rollback IMMEDIATE 不成功问题
查看>>
WCF揭秘——使用AJAX+WCF服务进行页面开发
查看>>
【题解】青蛙的约会
查看>>
IO流
查看>>
mybatis调用存储过程,获取返回的游标
查看>>
设计模式之装饰模式(结构型)
查看>>
面向对象的设计原则
查看>>
Swift3.0服务端开发(三) Mustache页面模板与日志记录
查看>>
EntityFrameWork 实现实体类和DBContext分离在不同类库
查看>>
autopep8
查看>>