Math, asked by alfred8882, 1 month ago

There were 2 jugs of water. Jug A had six times as much water as in Jug B.
After 1500 ml of water from Jug A was poured into Jug B, both jugs had the
same amount of water. What was the total amount of water in both jugs?

Answers

Answered by rahulshergill152
1

Answer:

The Two Water Jug Puzzle

You are on the side of the river. You are given a m liter jug and a n liter jug where 0 < m < n. Both the jugs are initially empty. The jugs don’t have markings to allow measuring smaller quantities. You have to use the jugs to measure d liters of water where d < n. Determine the minimum no of operations to be performed to obtain d liters of water in one of jug.

The operations you can perform are:

Empty a Jug

Fill a Jug

Pour water from one jug to the other until one of the jugs is either empty or full.

Recommended: Please solve it on “PRACTICE ” first, before moving on to the solution.

There are several ways of solving this problem including BFS and DP. In this article, an arithmetic approach to solving the problem is discussed. The problem can be modeled by means of the Diophantine equation of the form mx + ny = d which is solvable if and only if gcd(m, n) divides d. Also, the solution x,y for which equation is satisfied can be given using the Extended Euclid algorithm for GCD.

For example, if we have a jug J1 of 5 liters (n = 5) and another jug J2 of 3 liters (m = 3) and we have to measure 1 liter of water using them. The associated equation will be 5n + 3m = 1. First of all this problem can be solved since gcd(3,5) = 1 which divides 1 (See this for detailed explanation). Using the Extended Euclid algorithm, we get values of n and m for which the equation is satisfied which are n = 2 and m = -3. These values of n, m also have some meaning like here n = 2 and m = -3 means that we have to fill J1 twice and empty J2 thrice.

Now to find the minimum no of operations to be performed we have to decide which jug should be filled first. Depending upon which jug is chosen to be filled and which to be emptied we have two different solutions and the minimum among them would be our answer.

Similar questions