开发者

c++ program to solve a problem [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I am stuck with a c++ program which is an assignment.

Please help me out. Please suggest an approach if possible,

thanks in advance

Problem:

Given two vessels, one of which can accommodate a liters of water and the other which can accommodate b liters of water, determine the number of steps required to obtain exactly c liters of water in one of the vessels.

At the beginning both vessels are empty. The following operations are counted as 'steps':

  • emptying a vessel,
  • filling a vessel,
  • pouring water from one vessel to the other, without spilling, until one of the vessels is either full or empty.

Input

An integer t, 1<=t<=100, denoting the number of test cases, followed by t sets of input data, each consisting of three positive integers a (the number of liters the first container can hold), b (the number of liters the second container can hold), and c (the final amount of liters of water one vessel should contain), not larger than开发者_开发百科 40000, given in separate lines.


Sounds like a nice simple maths homework.

My advice, ignore any coding aspect for now, and concentrate on how you as a human would work it out given the two vessels in your hands.

You have 3 variables, the capacities of your vessels. x and y in this would be the quantities you need of a and b to work. Given at the time in question a, b and c will be replaced with numers.

In short, ax+by=c

So, if c is 12, and a is 2 and b is 3.

you have 2x+3b=12

now you have a simple equation

Given you know you want say 12 litres, work out in your head, how you would work it out if you were doing it yourself.

It sounds like you're asking for homework though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜