Problem # 18 : Die Hard
Remember the movie "Die Hard with a Vengeance" (*ing Bruce Willis. Third in a series of Die Hard movies).
Well
at one point in the movie
he was given two containers
one with
a capacity of 5 litres and the other with 3
and an endless supply of water.
To stop a bomb he needed exactly 4 litres of water.
This is what he did :-
Note in the example of the movie above Bruce Willis had A=5 B=3 C=4 and took n=6 steps.
The things you can do with your containers are :-
Sample Output
DIEHARD(3
2
2
1) should
return -1
DIEHARD(4
3
1
2) should
return -1
DIEHARD(4
4
1
5) should
return 0
DIEHARD(2
9
7
2) should
return -1
DIEHARD(2
9
5
5) should
return -1
NOTE: I couldn't find a particularly efficient algorithm for the above program myself. (Output for some test data took upto 2 minutes!!) So if you are able to create an efficient algorithm in Qbasic or C++ or Visual Basic please e-mail it to me.
![]() |