题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373
题目意思: 有两个class:A 和 B,Bob 在 Class A 里面。现在给出 Class A(n-1人) 和 Class B(m人) 所有人的分数,除了Bob,所以Class A 少了一个人。现在需要找出 Bob 最大可能的分数和最少可能的分数,使得他在Class A 里面拉低平均分,而在Class B 里面提高平均分。
由于数据量不大,所以可以暴力枚举。范围是两个class 中最小值和最大值之间。
这题应该是该赛区的签到题吧~~~~留个纪念^_^
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <limits.h> 5 #include <algorithm> 6 using namespace std; 7 8 const int maxn = 50 + 5; 9 int a[maxn], b[maxn]; 10 11 int main() 12 { 13 int t, n, m; 14 #ifndef ONLINE_JUDGE 15 freopen("input.txt", "r", stdin); 16 #endif 17 18 while (scanf("%d", &t) != EOF) 19 { 20 while (t--) 21 { 22 scanf("%d%d", &n, &m); 23 int minn = INT_MAX, maxx = INT_MIN; 24 double suma = 0, sumb = 0; 25 for (int i = 0; i < n-1; i++) 26 { 27 scanf("%d", &a[i]); 28 suma += a[i]; 29 minn = min(minn, a[i]); 30 maxx = max(maxx, a[i]); 31 } 32 33 for (int i = 0; i < m; i++) 34 { 35 scanf("%d", &b[i]); 36 sumb += b[i]; 37 minn = min(minn, b[i]); 38 maxx = max(maxx, b[i]); 39 } 40 41 double avga = suma /(n-1); 42 double avgb = sumb /m; 43 44 int minans = INT_MAX, maxans = INT_MIN; 45 46 for (int i = minn; i <= maxx; i++) 47 { 48 double add_suma = suma + i; 49 double add_sumb = sumb + i; 50 double new_avga = add_suma / n; 51 double new_avgb = add_sumb / (m+1); 52 53 if (new_avga < avga && new_avgb > avgb) 54 { 55 minans = min(minans, i); 56 maxans = max(maxans, i); 57 } 58 } 59 printf("%d %d ", minans, maxans); 60 } 61 } 62 return 0; 63 64 }