题目链接: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 中最小值和最大值之间。
这题应该是该赛区的签到题吧~~~~留个纪念^_^
#include <iostream>
#include <cstdio>
#include <cstring>
#include <limits.h>
#include <algorithm>
using namespace std; const int maxn = + ;
int a[maxn], b[maxn]; int main()
{
int t, n, m;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif while (scanf("%d", &t) != EOF)
{
while (t--)
{
scanf("%d%d", &n, &m);
int minn = INT_MAX, maxx = INT_MIN;
double suma = , sumb = ;
for (int i = ; i < n-; i++)
{
scanf("%d", &a[i]);
suma += a[i];
minn = min(minn, a[i]);
maxx = max(maxx, a[i]);
} for (int i = ; i < m; i++)
{
scanf("%d", &b[i]);
sumb += b[i];
minn = min(minn, b[i]);
maxx = max(maxx, b[i]);
} double avga = suma /(n-);
double avgb = sumb /m; int minans = INT_MAX, maxans = INT_MIN; for (int i = minn; i <= maxx; i++)
{
double add_suma = suma + i;
double add_sumb = sumb + i;
double new_avga = add_suma / n;
double new_avgb = add_sumb / (m+); if (new_avga < avga && new_avgb > avgb)
{
minans = min(minans, i);
maxans = max(maxans, i);
}
}
printf("%d %d\n", minans, maxans);
}
}
return ; }