저는 학교 프로그래밍 프로젝트를 진행하고 있으며 각 학생에게 그룹을 할당해야 모든 그룹 소녀들과 거의 같은 수의 남자 아이를 낳는다.여러 명의 학생을 대략 같은 수의 남학생과 여학생을 포함하는 방식으로 여러 그룹으로 나누는 방법
또한 기존 학생도 동일한 그룹을 유지하므로 처음에는 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
------------------------------------------
-Solution 얻을 수 : 나는 임의의 수의 유효 함을 할당을 만드는 방법을 알 필요가
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
:
Group A Group B
-------------- ---------------
Boys 13 Boys 13
Girls 11 Girls 10
-------------- ---------------
Total 24 Total 23
년 - 프로세스가 나는 다음과 같이이 솔루션은 도달 다음 이전에 배정 된 학생. 나는 또한 세 가지 그룹 (A, B 및 C)으로 동일한 프로세스를 수행해야합니다.
미리 감사드립니다.
귀하의 문제는 [배낭] (https://en.wikipedia.org/wiki/Knapsack_problem) 또는 [subsetsum] (https://en.wikipedia.org/wiki/Subset_sum_problem)으로 다항식으로 축소 될 수 있습니다. 문제. – Jan