微软公司招聘题目——狗的问题

原题:
一个大院子里住了50户人家,每家都养了一条狗,有一天他们接到通知说院子里有狗生病了,并要求所有主人在发现自己家狗生病的当天就要把狗枪杀掉。然而所有主人和他们的狗都不能够离开自己的房子,主人与主人之间也不能通过任何方式进行沟通,他们能做的只是通过窗户观察别人家的狗是否生病从而判断自己的狗病否。(就是说,每个主人只能看出其他49家的狗是不是生病,单独看自己的狗是看不出来的)
第一天没有枪声,第二天还是没有枪声,第三天传出一阵枪声,问有多少条狗被枪杀。
我的答案:

假设只有一只狗生病,那么第一天那个病狗的主人发现别人家的狗都没病,必然
就把自己的狗给杀了,第一天没枪声,说明至少有两只狗生病。
假设只有两只狗生病,那么第二天那两个病狗的主人发现别人家只有一只狗生病,
必然把自己的狗给杀了,第二天没枪声,说明至少有三只狗生病。
第三天有枪声,说明有三只狗生病,因为这样那三只病狗的主人发现别人家只有
两只狗生病,从此判断自己的狗也生病了,于是杀掉自己的狗。
因此有三条狗被杀。

~~~~~~~~~~~~~~~~~~~~~~~~~~~


基本假定:
确实有狗病了。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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值