Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Water Balancing between 4 Jugs Problem: Given 4 Jugs namely J 1 , J 2 , J 3 , J 4 with capacities [ C
Water Balancing between
Jugs
Problem:
Given Jugs namely with
capacities C C C C and initial
water content as S S S S
Goal:
Determine how many steps are needed
to achieve the final state of F F F F
by transferring water from one jug to
another without losing any water.
Constraints:
: for each :
Sum
Input:
Total number entries for each :
for each :
Sum
Input:
Total number entries
Question is to find minimum number of steps to make water in jars from initial to final. Question seems to be straight forward but I do not know what I am missing only half testcases passed.
So after checking edge cases like final state of no jar is greater than its capacity and total initial water is equal to total final water.
I tried some like this. Created variable less and more. less will store number of jars that will have less water in final jar than in initial jar and more will store number of jars that will have more water in final jar than in initial jar. If minless more then answer will be maxless more This can be justified. Lets say we have less water in one jar only this means at least one other jar has more water that we need to pour.
Take examples,
Initial
Final
In this case we need to pour water from jars that has more water, it can be or
In minless more means all are equal because only one jar can not have more or less water since total water is same so total more and total less should be same.
lets say
Initial
final
Like previous case minless more is and we need to pour all water from jars that has less water.
Case when less more I take all values of less and more and check if these are complimentary. For example if one jar has unit extra water then if another jar has unit less water then answer will be since these will complete each other. If not then answer will be because we either water to take some water from jar or give and all will interact if there are steps I am not sure I just tried multiple examples and this comes to be true comment if you get it wrong Want a C program solution for this problem
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started