拆分值成团均匀 [英] Splitting values into groups evenly

查看:110
本文介绍了拆分值成团均匀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我尝试解释的情况尽我所能。

Let me try to explain the situation the best I can.

可以说我有3个值

1, 2, 3

我告诉一个算法,这个值分成X列。比方说X = 2澄清。

I tell an algorithm to split this values into x columns. Lets say x = 2 for clarification.

该算法确定该组值中的最好的投入两列以下方式

The algorithm determines that the group of values is best put into two columns the following way.

1st column    2nd column
---------------------------
1             3
2

每个列有偶数个(总计,不是文字)值。

Each column has an even number (totals, not literals) value.

现在可以说我有以下值

7, 8, 3, 1, 4

我告诉大家,我想要的值分为3列的算法。该算法现在告诉我,以下是最合适的。

I tell the algorithm that I want the values split into 3 columns. The algorithm now tells me that the following is the best fit.

1st column    2nd column    3rd column
8             7             3
              1             4

注意列怎样的arent安静甚至,但它是接近,因为它可以得到的。多一点,有点下被认为是正常的,只要该列表是接近甚至也可以。

Notice how the columns arent quiet even, but it is as close as it can get. A little over and a little under is considered ok, as long as the list is AS CLOSE TO EVEN AS IT CAN BE.

任何人有什么建议吗?知道这样做有什么好的方法呢?

Anybody got any suggestions? Know any good methods of doing this?

推荐答案

我会做这样的:

  • add all the values, let's call this S
  • divide S by the number of columns, let's call this M.
  • find a set of values of which the sum is M or as close as possible to M, using a knapsack algorithm (e.g. http://search.cpan.org/~andale/Algorithm-Knapsack-0.02/lib/Algorithm/Knapsack.pm (just a quick Google on knapsack))
  • take the sum of the set of values and subtract it from S, let's call it T.
  • divide T by the number of columns minus 1
  • and repeat the algorithm

这篇关于拆分值成团均匀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆