Balancing Value Sets

So, I am working on an interesting little program and came across this rather interesting problem: I have several sets of values ​​of predefined set sizes. All of them are a unique subset of more values. The average values ​​of each subset of numbers should be as close to each other as possible. This should not be perfect, but should be close enough so that all sets are “balanced” against each other.

ex: {1,2,3,6,9,10,15,23,27} global average: 10,66 need to be sorted by 2 sets of 2 and one set of 5

Acceptable result: {1.27} {2.23} {3,6,9,10}

In practice, values ​​will range from 60 to 200, and sets will vary from size 6 to 20.

I tried several different algorithms with varying degrees of success, but I was interested to see what good people think of StackOverflow.

My best, Zach

+3
source share
2 answers

That sounds interesting. I would like to know what the practical application of this is.

To be sure, suppose you meant disjoint subsets, and the sum of the subsets was roughly equal (not average)

In addition, in the example, I could not understand how you decided (for sure) to make 2 sets of 2 and one of 5.

I can think of the greedy under the optimal solution.

  • Sort numbers in descending order. (smaller numbers surprise less, so deal later).
  • Determine the number of sets that you have. not too sure about it
  • ( robin )

.

1,2,3,6,9,10,15,23,27 : 27, 23, 15, 10, 09, 06, 03, 02, 01

27 3 2 1 = 33

23 09 = 30

15 10 06 = 31

0

RubyQuiz # 65, " " . , , , . , .

+2

Source: https://habr.com/ru/post/1751822/


All Articles