如何划分的阵列分成3份,每个部分大致相等的总和 [英] How to divide an array into 3 parts with the sum of each part roughly equal

查看:158
本文介绍了如何划分的阵列分成3份,每个部分大致相等的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安排数组,我希望把它分成3个部分,使它们的和最接近对方。

I have an arranged array and I want to divide it into 3 parts so that their sum are closest to each other.


Ex: I have this array:

    10, 8, 8, 7, 6, 6, 6, 5

so it'll be divided into 3 part like:

    p1 {10,8} sum = 18
    p2 {8,7,6} sum = 21
    p3 {6,6,5} sum = 17

推荐答案

楼主已经有一个工作溶液(在评论指出)到阵列分为两部分以相等的款项;称之为 split2 。由三部分组成的版本可以使用 split2 构造。

The original poster already has a working solution (noted in comments) to split the array into two parts with equal sums; call this split2. The three-part version can be constructed using split2.

  1. 添加到阵列的新号码等于三分之一原始数字的总和的
  2. 分割阵列分为两部分使用 split2
  3. 一个部分具有的溶液中加入的数量;将其删除。
  4. 采用分体式,另一部分为两个 split2
  1. Add to the array a new number equal to one-third of the sum of the original numbers.
  2. Split the array into two parts using split2.
  3. One part has the number that was added; remove it.
  4. Split the other part into two using split2.

这篇关于如何划分的阵列分成3份,每个部分大致相等的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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