“Empty the bucket”

Q:You are in the desert and you have 3 buckets of water containing a,b,c ounces respectively. Here a,b,c are positive integers. You need an empty bucket for an unspecified purpose. Being in the desert you need the water and cannot just pour it away. You have to pour the contents of one bucket into another one. BUT in any pouring, you must double the contents of the bucket which receives the water. For example the sequence of bucket contents could be:

3 2 1
1 4 1
0 4 2

Now show that no matter what a,b,c are, you can always manage to empty a bucket under this constraint.





A:首先考虑two-buckets的情形,假设(a,b)两个bucket分别为odd和even,在这两个bucket来回倒腾必然是一个死循环,但是由于每次倒取的数值是离散的,因此两个bucket之间状态数也是固定的,也就是在这个死循环的过程中存在周期性,经过有限步还会回到初始状态(a,b),那这一状态的前一步必须是(a+b/2,b/2)。这个规律在下面推理的过程中会用到。

好的,接下来考虑three-buckets的情形,先假设(a,b,c)为odd-even-even,

Algorithm:

    step1:假设b和c为even,且都不能被4整除(若能的话,skip step2);

    step2:在b和c之间倒腾一次,使得其中一个能被4整除;

    step3:重新编号(a,b,c)对应odd-even4-even2;

    step4:将two-buckets的结论用在a和b之间,即经过有限步达到(a+b/2,b/2,c)状态,此时可以看到odd桶的水增加了。

    step5:repeat (step1-step4),直到某个even bucket为空,Ends。

现在证明了odd-even-even的情形,其他情形如下:

    1) odd-odd-odd情况下可以通过任意一步倒腾变成odd-even-even;   

    2) odd-odd-even情况下通过倒腾两个odd buckets中的水得到odd-even-even;

    3) even-even-even情况可以将各个bucket中的水量除以2得到以上某种情形 ,用这个子问题的处理方式来映射原问题;


(Ref:The Puzzle Toad - 5

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值