Input : array of decimals ~ X
Output : array of int ~ Y
But they need to satisfy the condition:
sum(Y) = round(sum(x))
minmize (|y1-x1| + |y2-x2| + … + |yn-xn|)
input = 30.3, 2.4, 3.5
output = 30 2 4
input = 30.9, 2.4, 3.9
output = 31 2 4
round direction and then make up for the gap between the current sum and its original round sum.
If we select
floor then the gap will be made up by the
Note The biggest gap between the floor and original number is the smallest gap between the ceiling and original numbers.
Always welcome new ideas and
practical tricks, just leave them in the comments!