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分钟。