您的位置:首页 > 其它

zoj3819Average Score 类型转化 <求大于1个(double)数的整数,小于1个double类型的数的整数>

2015-08-16 23:40 387 查看
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) andM (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 A1,
A2, .., AN-1 representing the scores of other students in Bob's class.

The last line contains M integers B1, B2, ..,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

代码:

//在做这道题的时候,将四舍五入和这个取大于这个数的整数弄混了!呵呵,没事,反正
//能联想起来就行!求一个double类型的数让其四舍五入的话,就将其加上0.5取整就
//ok了,但是,在求一个double类型的大一点的整数,直接取整加1就行了,(因为小数一取整就也变成比它
//小的整数了,所以你再加1,肯定能得到你想要的整数);当你求一个比double类型
//小的数的时候,你就得看是不是整数了,如果是整数的话,你就得转化成(int型),然后再减1;
//如果是小数的话,直接转化成int型就行了!
#include <stdio.h>
#include <math.h>
int main()
{
int T,n,m,s1,s2;
int a[55],b[55];
double p1,p2;
scanf("%d",&T);
while(T--)
{
s1=s2=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n-1;i++)
{
scanf("%d",&a[i]);
s1+=a[i];
}
for(int i=1;i<=m;i++)
{
scanf("%d",&b[i]);
s2+=b[i];
}
p1=s1*1.0/(n-1);
p2=s2*1.0/m;
printf("%d ",(int)(p2)+1);
if(p1==(int)p1)
printf("%d\n",(int)p1-1);
else
printf("%d\n",(int)p1);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: