Other
Programming and Technical
Category
Your friend wants to set up a small scale industry which produces weights used in a
physical balance.
His customers are the shopkeepers located in his state. Each shopkeeper wants a set of
weighing objects using which he can produce all integer weights in range [1,n], where n may
vary for each shopkeeper. For a small grocery shop, n could be upto 50 Kg, and for a whole
sale shopkeeper n could be 1000 Kg. For a given n, a trivial solution is that the shopkeeper
keeps n weighing objects each of weight one kilogram. But it is very cumbersome to use and
manage so many weighing objects. So he wants the minimum number of weighing objects
using which he can weigh any object whose weight is in the range [1, n]. Such a set of
weighing objects is called a Min-weighing-objects(n) set. Such set need not be unique. For
example, {1, 3, 5} as well as {1, 2, 6} can serve to be a Min-weighing-objects(9) set.
Your friend wants to expand his business. So he wants to ensure that his customers get
full satisfaction. In particular, for a given n, he would like to present to the shopkeeper all
possible Min-weighing-objects(n) sets. The shopkeeper can place an order for the set of his
choice. Finally your friend delivers weights of that set to the shopkeeper. Your friend is
unable to come up with any solution to this problem. He approaches you with this problem.
Solve this problem. More formally, he wants you to write a program which for a positive
integer n, enumerates all Min-weighing-objects(n) sets.
Read Solution (Total 2)
-
- To weight any object the required set is m*{1,2,2,5,10,20,20}.Here m is no. of set.From the given set the max. weighing object is of 60 kg.
Now to weigh any object we require value of m i.e. n/60.
For e.g.( To weigh object of 1000kg. we require 1000/60 i.e.16.6 round it to 17 .i.e. we require 17 sets of {1,2,2,5,10,20,20}
[******IN MY PREVIOUS POST I HAD GIVEN THE WHOLE PROGRAM BUT IT IS NOT DISPLAYED COMPLETELY .SO I M GIVING IT AGAIN******]
#include
#include
void main()
{
int n,m;
clrscr();
coutn;
cout - 10 years agoHelpfull: Yes(1) No(0)
- //C++
#include
#include
void main()
{
int n,m;
clrscr();
coutn;
cout - 10 years agoHelpfull: Yes(0) No(1)
Other Other Question