题目链接:http://acm.tju.edu.cn/toj/showp2877.html
Time Limit: 3.0 Seconds Memory Limit: 65536K
Total Runs: 2713 Accepted Runs: 769 Multiple test files
In this problem we will investigate the maths behind this joke.
Problem specification
Given the list of student IQs for each of the two colleges, find the number of students of Computer Science that can make the joke true - that is, compute the size of the set { S | S is a student of Computer Science, and if he went to study Economics, both average IQs would increase }.Input
The first line of the input file contains an integer T specifying the number of test cases. Each test case is preceded by a blank line.Each test case looks as follows: The first line two positive integers NCS and NE - the number of students of Computer Science and Economics, respectively. The number of Computer Science students will be at least 2.
The following lines contain a total of NCS + NE whitespace-separated positive integers giving the IQs of all the students. The first NCS students mentioned in the input are Computer Science students, the remaining ones study Economics.
You can assume that both NCS and NE are not more than 200,000, and the IQ of each student is not more than 100,000
Output
For each test case output a single line with a single integer - the number of Computer Science students that would cause the funny event to happen.Sample Input
1 5 5 100 101 102 103 104 98 100 102 99 101
Sample Output
1
Hint: The average Computer Science IQ increases only if the leaving student is #1 or #2. Student #1 is too dumb to raise the average IQ for Economics, thus only student #2 remains and the answer is 1.
Source: TJU Team Selection Contest 2007 (4)
水题:
#include <stdio.h>
int main(){
int cs[200001],e,cast,ncs,ne,num;
double acs,ae;
scanf("%d",&cast);
while(cast--){
acs=ae=0;
num=0;
scanf("%d%d",&ncs,&ne);
for(int i=0;i<ncs;i++){
scanf("%d",&cs[i]);
acs+=cs[i];
}
for(int j=0;j<ne;j++){
scanf("%d",&e);
ae+=e;
}
acs/=ncs;ae/=ne;
for(int i=0;i<ncs;i++)
if(cs[i]<acs&&cs[i]>ae)
num++;
printf("%d\n",num);
}
}