微软公司招聘题目——狗的问题,这个是设计程序、开发程序很好的思路,考验一下你的智商吧-值得收藏
----------------------------精品word文档 值得下载 值得拥有----------------------------------------------
原题:
一个大院子里住了50户人家,每家都养了一条狗,有一天他们接到通知说院子里有狗生病
了,并要求所有主人在发现自己家狗生病的当天就要把狗枪杀掉。然而所有主人和他们的狗
都不能够离开自己的房子,主人与主人之间也不能通过任何方式进行沟通,他们能做的只是
通过窗户观察别人家的狗是否生病从而判断自己的狗病否。(就是说,每个主人只能看出其
他49家的狗是不是生病,单独看自己的狗是看不出来的)
第一天没有枪声,第二天还是没有枪声,第三天传出一阵枪声,问有多少条狗被枪杀。
我的答案:
假设只有一只狗生病,那么第一天那个病狗的主人发现别人家的狗都没病,必然
就把自己的狗给杀了,第一天没枪声,说明至少有两只狗生病。
假设只有两只狗生病,那么第二天那两个病狗的主人发现别人家只有一只狗生病,
必然把自己的狗给杀了,第二天没枪声,说明至少有三只狗生病。
第三天有枪声,说明有三只狗生病,因为这样那三只病狗的主人发现别人家只有
两只狗生病,从此判断自己的狗也生病了,于是杀掉自己的狗。
因此有三条狗被杀。
~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
基本假定:
确实有狗病了。every onwer is smart.
分析(ill dog=ig)
if ig=1, the owner of the dog kill his/her dog in the first day, since he/she finds there is no ill dog outside his house.
if ig=2, no body kills the dog in the first day, because they see at least 1 ig outside the their house.
the next day, everyone knows ig<>1, so if ig=2, the onwers of the two igs will kill his/her dos. so ig<>2.
ig=3 following ig=2's analysis, the third day, everone knows that ig<>1 or 2, the three onwers of the igs kill their dogs one by one or in the same time, because each of them see two igs outside.
so three dogs are killed.
ig=3 following ig=2's analysis, the third day, everone knows that ig<>1 or 2, the three onwers of the igs kill their dogs one by one or in the same time, because each of them see two igs outside.
so three dogs are killed.
----------------------------精品word文档 值得下载 值得拥有----------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------
----------------------------精品word文档 值得下载 值得拥有----------------------------------------------
这里的一天、两天、三天只是一个常量,只是一个固定的数字,没有什多大的意义,不要被
常量给迷惑了~这里还有一个隐含的条件,也就是说每天只能观察一条狗生病,其实三条狗
生病是最少的条件,也是数学当中求根的最小(最少)的条件。
----------------------------精品word文档 值得下载 值得拥有----------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------