|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- <?php
- function groupTwo($arr) {
- $n = count($arr);
- $v = array();
- $nice = array();
- for($i = 1; $i < $n - 1; $i++ ) {
- $group1 = [];
- $group2 = [];
- for($j = 0; $j < $n; $j++ ) {
- $group1 = array_slice($arr, $j, $i, true);
- $group2 = array_diff_key($arr, $group1);
- $diff[] = abs(array_sum($group1) - array_sum($group2));
- $all[] = array($group1, $group2);
- }
- }
- asort($diff);
- $zu = array_shift(array_keys($diff));
- return $all[$zu];
- }
- $arr = [155,110,120,1300,140,150,160,170,180,190,1001,160,170,180,190,3001];
- $best = groupTwo($arr);
- print_r($best);
复制代码
|
|