divide an integer into X parts (as even as possible)

时间:2014-08-26 05:20:04   收藏:0   阅读:301

the algorithm is like this: it evenly spreads an integer N over K cells.

for i = 0 to K
    array[i] = N / K    # integer division

# divide up the remainder
for i = 0 to N mod K
    array[i] += 1

 

原文:http://www.cnblogs.com/miaoz/p/3936329.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!