Question: ( 4 5 points ) You are given two bottles with integer capacities X and Y liters, respectively. Initially, there are x liters of water

(45 points) You are given two bottles with integer capacities X and Y liters, respectively. Initially, there are x liters of water in the first bottle, and y liters of water in the second bottle, where x, y are integers such that 0 x X and 0 y Y . At each step, you can perform one of the three operations below: - FILLUP(i). Fill up bottle i with tap water. - EMPTY(i). Pour all the water from bottle i to the drain. - POUR(i, j). Pour the water from bottle i to bottle j. After this operation, either bottle i is empty or bottle j is full while there may be some water left in bottle i. Your goal is to end up with exactly A liters of water in one of the two bottles, for some integer A max{X, Y }. Design an algorithm that takes as input integers X, Y, x, y, A, and achieves this goal by using the smallest number of operations, if at all possible. Your algorithm should either return the number of operations it performed until one of the two bottles contains A liters of water, or impossible. You should give the running time of your algorithm in terms of n = max{X, Y }.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!