四人过桥问题通解

Yes, there is a general solution for the four people bridge problem. The problem is that four people need to cross a bridge in 17 minutes at night with only one flashlight. The bridge can only hold two people at a time and they must have the flashlight to see. Each person takes a different amount of time to cross the bridge123.

The general solution is to have the two fastest people cross first, then one of them returns with the flashlight. Then, the two slowest people cross together, and the other fast person returns with the flashlight. Finally, the two fast people cross again124. This way, they can all cross in 17 minutes or less.

For example, if we have four people who take 1 minute (A), 2 minutes (B), 5 minutes © and 8 minutes (D) to cross respectively, then one possible solution is:

  • A and B cross together (2 minutes)
  • A returns with the flashlight (1 minute)
  • C and D cross together (8 minutes)
  • B returns with the flashlight (2 minutes)
  • A and B cross again (2 minutes)

The total time is 15 minutes.

Another example is if we have four people who take 10 minutes (W), 5 minutes (X), 2 minutes (Y) and 1 minute (Z) to cross respectively, then one possible solution is:

  • Y and Z cross together (2 minutes)
  • Z returns with the flashlight (1 minute)
  • W and X cross together (10 minutes)
  • Y returns with the flashlight (2 minutes)
  • Y and Z cross again (2 minutes)

The total time is 17 minutes.

是的,四人桥问题有一个通用的解决方案。问题是四个人在晚上只用一个手电筒就需要在 17 分钟内过一座桥。这座桥一次只能容纳两个人,他们必须有手电筒才能看到。每个人过桥所花的时间不同。

一般的解决办法是让两个跑得最快的人先过去,然后其中一个拿着手电筒返回。然后,两个最慢的人一起穿过,另一个快的人拿着手电筒返回。最后,两个快人再次交叉。这样,他们就可以在 17 分钟或更短的时间内全部通过。

例如,如果我们有四个人分别需要 1 分钟(A)、2 分钟(B)、5 分钟(C)和 8 分钟(D)穿过,那么一种可能的解决方案是:

A 和 B 一起穿过(2 分钟)
A带着手电筒返回(1分钟)
C和D一起穿过(8分钟)
B拿着手电筒返回(2分钟)
A和B再次穿过(2分钟)
总时间为15分钟。

再比如我们有四个人,分别用10分钟(W)、5分钟(X)、2分钟(Y)和1分钟(Z)过桥,那么一个可能的解法是:

Y 和 Z 一起穿过(2 分钟)
Z带着手电筒返回(1分钟)
W 和 X 一起过桥(10 分钟)
Y拿着手电筒返回(2分钟)
Y和Z再次过桥(2分钟)
总时间为17分钟。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值