我正在开展一个学校编程项目,我需要为每个学生分配一个小组,这样所有小组的男生人数与女生大致相同。
此外,旧学生保持同一组,因此我最初有2个小组(A和B),其中一些学生已经分配,还有一个列表来分配小组。每组允许的学生人数最多。
例如:
以前分配的学生数量:
Group A Group B
-------------- ---------------
Boys 6 Boys 12
Girls 9 Girls 8
-------------- ---------------
Total 15 Total 20
分配的学生数量:
-------------- ---------------
Boys 8 Girls 4
-------------- ---------------
- 每组学生人数最多:
------------------------------------------
25 students per group
------------------------------------------
- 要获得的解决方案:
Group A Group B
-------------- ---------------
Boys 13 Boys 13
Girls 11 Girls 10
-------------- ---------------
Total 24 Total 23
- 我达到此解决方案的过程如下:
1. I have calculated the total number of boys and girls:
Total Boys: 6 + 12 + 8 = 26
Total Girls: 9 + 8 + 4 = 21
2. I have calculated half of both amounts:
Total Boys: 26 / 2 = 13
Total Girls: 21 / 2 = 10 (10.5)
3. I have calculated the difference between the students assigned and the
students remaining to be assigned until the amount obtained previously:
Group A Group B
-------------- ---------------
Boys 13-6= 7 Boys 13-12= 1
Girls 10-9= 1 Girls 10-8= 2
-------------- ---------------
4. I have assigned the necessary amount of the students in each group:
Group A Group B
-------------- ---------------
Boys 6+7= 13 Boys 12+1= 13
Girls 9+1= 10 Girls 8+2= 10
-------------- ---------------
Total 23 Total 23
5. And finally the one that I have left I have added it to the first
group:
Group A Group B
-------------- ---------------
Boys 13 Boys 13
Girls 10+1=11 Girls 10
-------------- ---------------
Total 24 Total 23
我需要知道如何使作业对任何数量的先前分配的学生有效。我还需要对三组(A,B和C)进行相同的处理。
提前致谢
答案 0 :(得分:1)
您提出的解决方案很好。
请记住,将学生人数除以step #2
中的小组数。这应该足以使您的解决方案变得灵活。