Three Thief need to cross a river. Each thief has certain amount of stolen gold coins kept in his bag.
Thief A has 1000 gold coins
Thief B has 700 gold coins
thief C has 300 gold coins
To cross the river there is a boat which can carry a maximum of two objects at a time that means either a maximum of two thieves can cross the river or a thief with a bag can cross the river. The problem is that in this process of crossing the river if a thief is left with an amount of coins more than his own then he will run away with that. The same rule applies for two thieves, if they are left with a total of more than their cumulative gold coins then they will run away with that money.
What strategy will ensure that they all cross the river properly ?
Solution: They all will cross the river in following manner.
- Thief B crosses first with his bag of 700 coins. He will keep the bag there and will return back.
- Thief A will now cross the river with the bag which has 300 coins. He will keep the bag and return back.
- Now thief B and C cross the river and thief C will return back with his bag of 300 coins.
- Now thief A goes to the other side with his bag of 1000 coins and thief B will return back with his bag of 700 coins.
- Now thief B and C cross the river together and thief A return back empty handed. Thief A takes the bag of 300 coins and cross the river then thief B is sent to collect his bag of 700 coins.
So, finally they all cross the river properly.
This article is contributed by R_Raj. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.