Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Need help with sorting algorithm

Name: Anonymous 2011-07-01 8:54

help /prog/,
I am really bad with all kinds of sorting algorithms
and now I need to write a really complex one:
I got 10 instances, each consisting of two integers.
Now I want to put them into two halves, 5 in each.
However the sum of the first integer in each of both halves got to be as close to the sum of the other half as possible,
while keeping the sums of the second integers as close as possible, too.
e.g.:
a: 7, 800
b: 4, 500
c: 6, 700
d: 1, 100
e: 1, 200
f: 5, 900
g: 4, 700
h: 2, 300
i: 9, 400
j: 3, 900

becomes:
i: 9, 400
f: 5, 900
b: 4, 500
h: 2, 300
d: 1, 200
---------- sum: 21, 2300
a: 7, 800
c: 6, 700
g: 4, 700
j: 3, 900
e: 1, 100
---------- sum: 21, 3200

becomes:
i: 9, 400
g: 4, 700
b: 4, 500
j: 3, 900
d: 1, 200
---------- sum: 21, 2700
a: 7, 800
c: 6, 700
f: 5, 900
h: 2, 300
e: 1, 100
---------- sum: 21, 2800

does anyone have an idea how to set up a sort, which returns these results?

Name: Anonymous 2011-07-01 9:48

>>7
Forget it, the partition problem is NP-complete.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List