Raised This Month: $ Target: $400
 0% 

Balancing Sides


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 07-24-2010 , 17:26   Re: Balancing Sides
Reply With Quote #5

Your solution will not work well with this: 250, 50, 50, 50, 50, 50, 1, 1, 1, 1

I would recommend something like this:
PHP Code:
new numbers[10] = { 1536749102}
new 
group[2][5]
new 
group_cnt[2]
new 
group_sum[2]

for(new 
i=0i<10i++){
    if(
group_cnt[1] >= || (group_cnt[0] < && group_sum[0] <= group_sum[1])){
        
group[0][group_cnt[0]++] = numbers[i
        
group_sum[0] += numbers[i
    }else{
        
group[1][group_cnt[1]++] = numbers[i]
        
group_sum[1] += numbers[i]
    }

It will have better effect if you sort numbers in descending order.
__________________
Impossible is Nothing

Last edited by Sylwester; 07-24-2010 at 17:29.
Sylwester is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode