Question: ( 4 5 points ) You are given two bottles with integer capacities X and Y liters, respectively. Initially, there are x liters of water
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 x X and y Y At each step, you can perform one of the three operations below: FILLUPi Fill up bottle i with tap water. EMPTYi Pour all the water from bottle i to the drain. POURi 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 maxX 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 maxX Y
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
