Hi,
Any input for a way to split std :: vector into two equal parts? I need to find the smallest possible difference between | part1 - part2 |.
This is how I do it now, but from what you can probably say, in some cases it will not give an optimal split.
auto mid = std::find_if(prim, ultim, [&](double temp) -> bool
{
if(tempsum >= sum)
return true;
tempsum += temp;
sum -= temp;
return false;
});
The vector is sorted, from highest to lowest, the values ββcan actually be displayed twice. I do not expect part1 and part2 to have the same number of elements, but the sum (part1) should be as close as possible to the sum (part2)
For example, if we had {2.4, 0.12, 1.26, 0.51, 0.70}, the best split would be {2.4, 0.12} and {1.26, 0.51, 0.70}.
If this helps, I am trying to achieve a separation algorithm for encoding Shannon Fano.
, , , http://en.wikipedia.org/wiki/Shannon%E2%80%93Fano_coding#Example
, !