python-3.x 如何使任务在给定的人数之间进行近似相等的分配?

cotxawn7  于 2022-12-01  发布在  Python
关注(0)|答案(1)|浏览(123)

假设任务是在3个人之间划分33张table。如果平均划分,则输出为[11, 11, 11],如果table数量为35张,则输出应为[12, 12, 11]
当我试图除法时,我得到了[11, 11, 11, 1, 1]。我需要帮助在python中解决这个问题。这是我主要问题陈述的一部分。
下面是我的代码:

div2 = count2 // len(ri_ot_curr) # equal division of other tables
rem2 = 0
rem2 = count2 % len(ri_ot_curr) # remaining tables tables unallocated
for i in range(len(ri_ot_curr)):
    c = 0
    for start in range(len(tft)):
        if tft.loc[start, 'Release Date'] == 'Release '+str(release_date) a: #some condition
            tft.loc[start, 'Quant RI - Table'] = ri_ot_curr[i]
            tft.loc[start, 'Date'] = date_tft()
            c = c+1
            if c == div2:
                break

    if rem2 > 0:

         ri_ot_rem = random.sample(ri_ot_curr, rem2)
         for i in range(len(ri_ot_rem)):
             for start in range(len(tft)):
                 if tft.loc[start, 'Release Date'] == 'Release '+str(release_date):#some condition
                     tft.loc[start, 'Quant RI - Table'] = ri_ot_rem[i]
                     tft.loc[start, 'Date'] = date_tft()   
                     break
xwbd5t1u

xwbd5t1u1#

我希望我理解你正确,如果我这样做这个代码将做的伎俩:

number_of_tables = 35
number_of_people = 3

tables_list = [int(number_of_tables / number_of_people) for _ in range(number_of_people)]

remainder = number_of_tables % number_of_people

for index in range(remainder):
    tables_list[index] += 1

print(tables_list)

相关问题