Answer the question
In order to leave comments, you need to log in
How to evenly distribute banknotes by amounts?
The disposition is as follows - there is a certain number of banknotes of different denominations (for example, the ruble line is 100,200,500,1000,2000,5000). It is necessary to divide the banknotes into N parts. The sizes of the parts are known. Task: determine how many banknotes and what denomination will be in each of the parts. At the same time, it is desirable that the distribution over banknotes be uniform. Help solve math. It is necessary for the subsequent implementation in the code.
Answer the question
In order to leave comments, you need to log in
Initial data
a) array [{value, quantity},...,{value, quantity}]
b) Number of parts
It is required to construct b - arrays.
Checks for the existence of a solution
S = by array a_n*a_c ; // sum to distribution
Sb = S/b ; // To each - Must be whole, otherwise it is impossible to divide equally.
there should not be banknotes with a face value greater than Sb; // tearing and taking change is not allowed.
and then it’s easier to solve math with heuristics than
https://ru.wikipedia.org/wiki/%D0%97%D0%B0%D0%B4%D...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question