Zoj problem set-3819 average score
Question Link
The score of one of the two students (Class A and Class B) is not given. Now you are asked to give the upper and lower limit of the student's score, so that the student's score is satisfied and the student's score is put out of class A to Class B, the average score of both classes is increased.
Solution:
Sa: indicates the total score of the students in Class A, and SB: indicates the total score of the students in Class B;
N: Total number of students in Class A; M: Total number of students in Class B;
X indicates the score of the student.
Satisfied: 1. (SA + x)/n <SA/(n-1); 2. (Sb + x)/(m + 1)> Sb/m;
D: Sb/(m + 1) <x <SA/(n-1) Note: The integer is obtained.
Code:
#include <cstdio>#include <cstring>int main () { int T; int n, m; int score; scanf ("%d", &T); while (T--) { int sum1 = 0; int sum2 = 0; scanf ("%d%d", &n, &m); for (int i = 0; i < n - 1; i++) { scanf ("%d", &score); sum1 += score; } for (int i = 0; i < m; i++) { scanf ("%d", &score); sum2 += score; } if (sum1 % (n - 1) == 0) sum1 = sum1 / (n - 1) - 1; else sum1 = sum1 / (n - 1); sum2 = sum2 / m + 1; printf ("%d %d\n", sum2, sum1); } return 0;}
Zoj problem set-3819 average score