Milk Man and His Bottles

A Milkman serves milk in packaged bottles of varied sizes. The possible size of the bottles are {1, 5, 7 and 10} litres. He wants to supply desired quantity using as less bottles as possible irrespective of the size. Your objective is to help him find the minimum number of bottles required to supply the given demand of milk.
Input Format:
First line contains number of test cases N
Next N lines, each contain a positive integer Li which corresponds to the demand of milk.
Output Format:
For each input Li, print the minimum number of bottles required to fulfill the demand
Constraints:
1 <= N <= 1000
Li > 0
1 <= i <= N
Sample Input and Output
SNo. Input Output
1
2
17
65
2
7
Explanation:
Number of test cases is 2
1. In first test case, demand of milk is 17 litres which can be supplied using minimum of 2 bottles as follows
o 1 x 10 litres and
o 1 x 7 litres
2. In second test case, demand of milk is 65 litres which can be supplied using minimum of 7 bottles as follows
o 6 x 10 litres and
o 1 x 5 litres

Showing Answers 1 - 7 of 7 Answers

john

  • Aug 7th, 2015
 

Code
  1. span style="color: #ff0000;">"Enter the number of puk

  2. ");

  3.    scanf("%d""First %d terms of fate sanka are :-

  4. ""%d

  5. "

  Was this answer useful?  Yes

john

  • Aug 7th, 2015
 

Code
  1. #include <stdio.h>

  2. #include <stdlib.h>

  3.  

  4. #define ARRAYSIZE(a) (sizeof(a))/(sizeof(a[0]))

  5. // prints subset found"%*d""

  6. ");

  7. }

  8.  

  9. // inputs

  10. // s            - set vector

  11. // t            - tuplet vector

  12. // s_size       - set size

  13. // t_size       - tuplet size so far

  14. // sum          - sum so far

  15. // ite          - nodes count

  16. // target_sum   - sum to be found// We found subset// Exclude previously added item and consider next candidate// generate nodes along the breadth// consider next level node (along depth)

  17.             subset_sum(s, t, s_size, t_size + 1, sum + s[i], i + 1, target_sum);

  18.         }

  19.     }

  20. }

  21.  

  22. // Wrapper to print subsets that sum to target_sum

  23. // input is weights vector and target_sum"Nodes generated %d

  24. "#include <stdio.h>

  25. #include <stdlib.h>

  26.  

  27. #define ARRAYSIZE(a) (sizeof(a))/(sizeof(a[0]))

  28. // prints subset found"%*d""

  29. suls");

  30. }

  31.  

  32. // qsort compare function// inputs

  33. // s            - set vector

  34. // t            - tuplet vector

  35. // s_size       - set size

  36. // t_size       - tuplet size so far

  37. // sum          - sum so far

  38. // ite          - nodes count

  39. // target_sum   - sum to be found// We found sum// constraint check// Exclude previous added item and consider next candidate// constraint check// generate nodes along the breadth// consider next level node (along depth)

  40.                     subset_sum(s, t, s_size, t_size + 1, sum + s[i], i + 1, target_sum);

  41.                 }

  42.             }

  43.         }

  44.     }

  45. }

  46.  

  47. // Wrapper that prints subsets that sum to target_sum// sort the set//mlikman will save you from code vita"pukss generated %d

  48. "

  Was this answer useful?  Yes

Ritobrata Choudhury

  • Aug 7th, 2015
 

Code
  1. #include<stdio.h>

  2. //printf("Enter Number of test cases:--");

  3.     scanf("%d"//printf("Enter a number >0:--");

  4.         scanf("%d""%d

  5. ",a[i]);

  6.     }

  7.  

  8. }

  9.  

  Was this answer useful?  Yes

Bikash Choudhury

  • Aug 27th, 2015
 

Code
  1. #include<iostream>

  Was this answer useful?  Yes

lavanya

  • Jul 19th, 2016
 

Code
  1. #include<stdio.h>

  2. "%d""%d""%d

  3. "

  Was this answer useful?  Yes

t3chn0tr0n

  • Jun 26th, 2019
 

Here is a take in Python.
Hope this helps.

Code
  1.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions