zoj3819Average Score
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 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
题意:有两个班的同学,其中bob在第一班,然后输入每个班同学的成绩,如果bob属于二班的时候,两个班的平均分都会提高,求bob得分的上下限
分析:bob成绩大于二班平均分,小于一班其他的平均分。我用double存总分,在求最后结果时纠结了好久,上限<平均分,如果平均分是整数的话就是-1,不是整数直接强制转换,下限>平均分,不管平均分怎样都直接+1;
其实后来又搜了一下别人写的,发现直接用int就ok,而且还方便,便于求那个平均分是不是整数,直接取模
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int main()
{
int t;
scanf("%d", &t);
for(int k = ; k <= t; k++)
{
int n,m,score;
double scoren = ,scorem = ;
scanf("%d%d", &n, &m);
for(int i = ; i <= n - ; i++)
{
scanf("%d", &score);
scoren += score;
}
for(int i = ; i <= m; i++)
{
scanf("%d", &score);
scorem += score;
}
printf("%d ",(int) ( scorem / m + ) );
if(scoren / (n - ) == (int) scoren / (n - )) //这里一直不确定是不是可行,
printf("%d\n",(int) ( scoren / (n -) - ));
else
printf("%d\n", (int) (scoren / (n - ) ));
} return ;
}
zoj3819Average Score的更多相关文章
- Lucene的评分(score)机制研究
首先,需要学习Lucene的评分计算公式—— 分值计算方式为查询语句q中每个项t与文档d的匹配分值之和,当然还有权重的因素.其中每一项的意思如下表所示: 表3.5 评分公式中的因子 评分因子 描 述 ...
- 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。
一. 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...
- 关于一道数据库例题的解析。为什么σ age>22 (πS_ID,SCORE (SC) ) 选项是错的?
本人大二学子.近段时间在做数据库复习题的时候遇到一道题,如下. 有关系SC(S_ID,C_ID,AGE,SCORE),查找年龄大于22岁的学生的学号和分数,正确的关系代数表达式是( ) . ⅰ. πS ...
- 利用SCORE法则来总结一次偷懒的单元测试过程
最近遇到一个单元测试的问题,本周正好学个了一个SCORE法则,这里正好练练手应用此法则将问题的前因后果分享给大家. S:背景 代码要有单元测试,检测的标准就是统计代码的单元测试覆盖率,程序员需要达到 ...
- Hiho coder 1236 2015 北京网络赛 Score
五维偏序..一开始被吓到了,后来知道了一种BITSET分块的方法,感觉非常不错. 呆马: #include <iostream> #include <cstdio> #incl ...
- Java-集合-第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList(); l
第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; ...
- 第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList();
list.add(new Student("Tom", 18, 100, "class05")); list.add(new Student("Jer ...
- Competition-based User Expertise Score Estimation-20160520
1.Information publication:sigir 2011 author:Jing Liu Harbin Institute of TechnologyMicrosoft Researc ...
- linux 终端报错 Out of memory: Kill process[PID] [process name] score问题分析
从Out of memory来看是内存超出了,后面的 Kill process[PID] [process name] score好像和进程有关了,下面我们就一起来看看linux 终端报错 Out o ...
随机推荐
- 微软职位内部推荐-SW Engineer II for Skype
微软近期Open的职位: We are the Skype Beijing team. Skype division drives the communications strategy for Mi ...
- 一个按钮,如果5分钟内点击再次点击给予提示操作频繁,在JS里可以这样写
很简单. 但是,如果你要离开这个页面再进来, 就没办法限制了. 除非用cookie 储存状态 给个示例 var isLock = flase; //定义全局变量 按钮点击事件: if(isLock){ ...
- listview的头布局把我的ACTION_DOWN事件给吃了.....
因为头布局的viewpager自己处理点击事件 public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getAction()) ...
- 又折腾到这么晚 , 图片Viewpager PagerIndicator,listview 和侧边栏滑动的事件处理
代码 思路 根据坐标判断 事件是否拦截 调用 getParent().requestDisallowInterceptTouchEvent(true);方法告诉上层ViewGroup 是否拦截 返回t ...
- jquery-lazyload延迟加载图片 及 加载顺序 bug 修复
jquery-lazyload延迟加载图片 代码修改片段 function update() { var counter = 0; /**fix by weiyj start***/ elemen ...
- 将matlab中数据输出保存为txt或dat格式
:FID= FOPEN(filename,permission) 用指定的方式打开文件 FID=+N(N是正整数):表示文件打开成功,文件代号是N. FID=-1 : 表示文件打 ...
- 浪潮之巅IT那点事之一——AT&T的兴衰
首次接触到<浪潮之巅>这本书,几乎是熬了一个通宵把上下两册全部看完,感慨颇多.从事计算机基础教育多年,每次在讲计算机导论课程时,总是在重复同样的内容,讲一些计算机结构.操作系统.算法.软件 ...
- 如何下载struts 2及其各个包的作用
一.http://archive.apache.org/dist/struts/library/ 二. struts官网: http://struts.apache.org/ 进入主页后点击" ...
- 20145215实验三 敏捷开发与XP实践
20145215实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验步骤 (一)敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法应用到软件的开发.运营和维护上的过程.软 ...
- MATLAB仿真总结
MATLAB仿真过程中,编写MATLAB代码的时候犯了很多错误,做了很多蠢事.记录下自己犯错的点点滴滴,并引以为戒.使用MATLAB版本为2014a,以下内容如有不当还请指正. 1. 仿真开始前清理工 ...