Bridge and torch Problem

Source: Internet
Author: User

Bridge and torch Problem

From http://en.wikipedia.org/wiki/Bridge_and_torch_problem

Bridge Problems

Said, it was dark and four people had to bridge the bridge. They had only one torch. A bridge can only let two people pass at a time, and because it is dark, people crossing the bridge must have a torch. It is known that the time required for crossing A, B, C, and D is 1, 2, 5, or 8 (minutes). Find the shortest time required for crossing a bridge.

Method 1:

Obviously, every time two people pass, one person must come back to deliver the torch. The cost of returning is unavoidable, so we will let people who bridge the bridge back in one minute, so that the waste of time is the shortest.

Elapsed time

Start Point

Action

Endpoint

0

A B c d

   

2

C d

A and B in the past, it took 2 minutes

A B

3

A c d

A: It will take 1 minute.

B

8

D

A and C used to take 5 minutes.

A B C

9

A D

A: It will take 1 minute.

B c

17

 

A and D used to take 8 minutes.

A B c d

Therefore, this solution takes 17 minutes.

Method 2:

If the slowest person passes, the time consumed by two people is only one time. So let the slowest two people pass. Let the shortest run before, and then he takes back the torch.

Elapsed time

Start Point

Action

Endpoint

0

A B c d

   

2

C d

A and B in the past, it took 2 minutes

A B

3

A c d

A: It will take 1 minute.

B

11

A

C and D Cross used to take 8 minutes

B c d

13

A B

B. It takes 2 minutes.

C d

15

 

A and B in the past, it took 2 minutes

A B c d

This solution takes 15 minutes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.