F
F
FlashHaos2016-08-29 23:01:22
css
FlashHaos, 2016-08-29 23:01:22

How to split an array into groups with equal sums in each group?

Colleagues, tell me an algorithm that can be used to split an array of numbers into n groups so that the sums of numbers in each group are as close as possible?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
Сергей delphinpro, 2016-06-20
@3dben

codepen.io/anon/pen/mErzbV

Андрей, 2016-06-20
@AndreyMyagkov

Дизайнер ушлёпок! Если начал рисовать под сетку, так что ему мешало сдвинуть 1-й и 3-й блок по центру?)

Александр Ружевич, 2016-06-20
@ruzhevich

как написали выше, родительский блок поставте по центру, затем внутри 5 блоков float:left; или display:inline-block; все оч просто)

B
bl1nder, 2016-06-21
@bl1nder

Попробуйте flexbox:
frontender.info/a-guide-to-flexbox
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
www.sketchingwithcss.com/samplechapter/cheatsheet.html

X
xmoonlight, 2016-08-30
@xmoonlight

The sum of the entire array must be divided into the number of groups (compare the arithmetic number in the group to which we will strive) and in turn type into groups, starting from the largest digit (element value) from the array. As soon as the sum in the group exceeds the arithmetic mean, skip and go to the next group, and so on until the smallest of the entire array remains, which, after the 1st excess cycle, falls into the group with the smallest excess of the target sum.
PS: an indiscreet question is possible: why would this be useful?

A
Andrew, 2016-08-30
@OLS

Read the algorithms of the rucksack packing problem - you get a variation of it with a common penalty for several rucksacks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question