Average Score


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Bob is a freshman in Marjar University. He is clever and diligent. However, he is not good at math, especially in Mathematical Analysis.

After a mid-term exam, Bob was anxious about his grade. He went to the professor asking about the result of the exam. The professor said:

"Too bad! You made me so disappointed."

"Hummm... I am giving lessons to two classes. If you were in the other class, the average scores of both classes will increase."

Now, you are given the scores of all students in the two classes, except for the Bob's. Please calculate the possible range of Bob's score. All scores shall be integers within [0, 100].

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains two integers N (2 <= N <= 50) and M (1 <= M <= 50) indicating the number of students in Bob's class and the number
of students in the other class respectively.

The next line contains N - 1 integers A1A2, .., AN-1 representing the scores of other students in Bob's
class.

The last line contains M integers B1B2, .., BM representing the scores of students in the other class.

Output

For each test case, output two integers representing the minimal possible score and the maximal possible score of Bob.

It is guaranteed that the solution always exists.

Sample Input

2
4 3
5 5 5
4 4 3
6 5
5 5 4 5 3
1 3 2 2 1

Sample Output

4 4
2 4

Author: JIANG, Kai

Source: The 2014 ACM-ICPC Asia Mudanjiang Regional Contest

解题思路:

题意为 bob所在的班有n个人,每人都有一个成绩,另外一个班有m个人。没人都有一个成绩,假设把bob放到还有一个班里去。那么两班的平均分都比原来的班内平均分要高,问符合条件的bob的成绩的范围。

枚举就可以。

代码:

#include <iostream>
#include <cmath>
using namespace std;
int t;
double a[52];
double b[52];
int n,m;
int bob;
int s,e; int main()
{
cin>>t;
while(t--)
{
cin>>n>>m;
double sum1=0.0;
double sum2=0.0;
double pre1,pre2;
for(int i=1;i<=n-1;i++)
{
cin>>a[i];
sum1+=a[i];
}
for(int i=1;i<=m;i++)
{
cin>>b[i];
sum2+=b[i];
}
bool first=0;
for(bob =0;bob<=100;bob++)
{
pre1=(sum1+bob)/n;
pre2=(sum2)/m;
if((sum1)/(n-1)>pre1&&(sum2+bob)/(m+1)>pre2)
{
if(first)
e=bob;
if(!first)
{
s=bob;
e=bob;
}
first=1;
} }
cout<<s<<" "<<e<<endl;
}
return 0;
}

[ACM] ZOJ 3819 Average Score (水题)的更多相关文章

  1. ZOJ 3819 Average Score 水

    水 Average Score Time Limit: 2 Seconds      Memory Limit: 65536 KB Bob is a freshman in Marjar Univer ...

  2. ZOJ 3819 Average Score(平均分)

    Description 题目描述 Bob is a freshman in Marjar University. He is clever and diligent. However, he is n ...

  3. zoj 3819 Average Score

    Average Score Time Limit: 2 Seconds      Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...

  4. ZOJ 3819 Average Score(数学 牡丹江游戏网站)

    主题链接:problemId=5373">http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 Bob is ...

  5. ZOJ 2819 Average Score 牡丹江现场赛A题 水题/签到题

    ZOJ 2819 Average Score Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge ...

  6. UVa 1585 Score --- 水题

    题目大意:给出一个由O和X组成的串(长度为1-80),统计得分. 每个O的分数为目前连续出现的O的个数,例如,OOXXOXXOOO的得分为1+2+0+0+1+0+0+1+2+3 解题思路:用一个变量t ...

  7. hdu 5268 ZYB loves Score 水题

    ZYB loves Score Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  8. ZOJ 3827 Information Entropy 水题

    Information Entropy Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/sh ...

  9. 咸鱼的ACM之路:DFS水题集

    DFS的核心就是从一种状态出发,转向任意的一个可行状态,直到达到结束条件为止.(个人理解) 下面全是洛谷题,毕竟能找到测试点数据的OJ我就找到这一个....在其他OJ上直接各种玄学问题... P159 ...

随机推荐

  1. Spring Cloud (14) 服务网关-过滤器

    Spring Cloud Zuul作为网关所具备的最基本的功能:路由,还具备另外一个核心的功能:过滤器. 过滤器 通过Spring Cloud Zuul实现的路由功能,我们的微服务可以通过统一的API ...

  2. MVC系列学习(八)-分布视图

    1.本次学习实例 1.1.建议:为了尽可能让项目简单,就新建一个空的mvc项目,同时添加任何视图不用模板页 1.2注意:在添加LoginPart的分部视图时,要记得沟一个沟 2.项目代码,如下 总共三 ...

  3. bindColumn、bindParam与bindValue的区别

    bindColumn:绑定一列到一个 PHP 变量(类似于list()函数为变量赋值) <?php //连接数据库函数 functionconnect() { try { $dbh = new ...

  4. c++将bool变量以文字形式打印

    #include <iostream> // std::cout, std::boolalpha, std::noboolalpha int main () { bool b = true ...

  5. CSS固定布局:960GS

    960栅格系统 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  6. Stanford coursera Andrew Ng 机器学习课程第二周总结(附Exercise 1)

    Exercise 1:Linear Regression---实现一个线性回归 重要公式 1.h(θ)函数 2.J(θ)函数 思考一下,在matlab里面怎么表达?如下: 原理如下:(如果你懂了这道作 ...

  7. nuxt https

    我用的模板是nxut-express,版本是:1.4.2.服务器:阿里云.一.申请免费证书:网站能通过https访问,首先得申请https证书,付费的阿里云上有售卖的,一年几千块.免费的可以通过cer ...

  8. sql的四种连接方式

    1.内联接.(典型的联接运算,使用像 =  或 <> 之类的比较运算符).包括相等联接和自然联接. 内联接使用比较运算符根据每个表共有的列的值匹配两个表中的行.例如,检索 students ...

  9. iptables详解(4):iptables匹配条件总结之一

    所属分类:IPtables  Linux基础 在本博客中,从理论到实践,系统的介绍了iptables,如果你想要从头开始了解iptables,可以查看iptables文章列表,直达链接如下 iptab ...

  10. enote笔记语言(5)——其他

    章节:其他   ((主:单词))                               用来醒目地强调这个句子中哪个词语作主语 sentence:                         ...