Question: How to solve this problem in c + + ? ( Method ) using varience take the scores of n students as input, sort them,

How to solve this problem in c++?
(Method)using varience
take the scores of n students as input, sort them, and then
divide them into k groups.
Again, assume that lower group numbers correspond to higher scores.
It would be ideal if the scores of students within each group were
similar.
Therefore, calculate the variance of student scores in each group, and
aim to minimize the sum of these variances across all groups.
However, each group must have at least one student, and the variance
of a group with only one student is considered to be 0
Take input from standard input.
The first line contains n and k.
The next line contains the scores of n students in ascending order of
enrollment numbers.
Here, n is a number greater than or equal to k.
Each score can range from 0 to 1,000, and ties are possible.
Surprisingly, n can be as large as 104
.
k is a positive integer less than or equal to 12.(Note: depending on the
school, each grade (A, B, C, D) may be divided into 2 or 3 categories)
Print the (minimum) sum of variances in Method 2 on the second line
of standard output (rounded to three decimal places).
Write the groups from Method 2 to a file (filename: Partition2.txt).
The first line of the file corresponds to Group 1, and the k
th line
corresponds to Group k. Each line lists "student number (student
score)" in ascending order of student numbers.
Example of Input and Output
Input (standard/console input)
153
50851035451575802530556065705
Output (standard/console output)
197.917
Output (filename: Partition1.txt)
2(85)7(75)8(80)13(65)14(70)
1(50)5(45)11(55)12(60)
3(10)4(35)6(15)9(25)10(30)15(5)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!