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].
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.
It is guaranteed that the solution always exists.
Author: JIANG, Kai
Source: The 2014 ACM-ICPC Asia Mudanjiang Regional Contest
代码:
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 integerT 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; }
相关文章推荐
- zoj 3822 Domination 【概率DP 求期望】
- C,C++宏中#与##的讲解
- android中关于真实手机测试的问题及解决方案
- VMware下安装linux系统
- 【1】安装rabbitmq server
- u3d菜鸟入门:unity中物体旋转初探
- 《Apple Watch 开发》UI 布局、大小等基本控制
- Spring Aop详尽教程
- 开发java程序的基本步骤:程序的编译与运行
- 数据结构 二叉树遍历之前序、中序、后序以及层次遍历实现
- 单例模式
- Linux下高并发socket最大连接数所受的限制问题
- 阻塞/非阻塞与异步/同步
- linux中的文件压缩和文件解压缩
- ZOJ 3690 & HDU 3658 (矩阵快速幂+公式递推)
- Vanya and Table
- Wireshark图解教程(简介、抓包、过滤器)
- 大型网站架构演变和知识体系
- Java-拾遗:接口
- Html5 Canvas笔记(3)-Canvas状态