⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toj_2877.cpp

📁 Tianjin University Online Judge 的80多道题目 .
💻 CPP
字号:
/*2877.   Paradox With Averages Time Limit: 3.0 Seconds   Memory Limit: 65536KTotal Runs: 290   Accepted Runs: 152    Multiple test filesOne well-known joke goes as follows: If a bad Computer Science student drops out of college and goes to a different college to study Economics instead, he will increase the average intelligence on both colleges.In this problem we will investigate the maths behind this joke.Problem specificationGiven 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 }.InputThe 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,000OutputFor 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 Input15 5100 101 102 103 10498 100 102 99 101Sample Output1Hint: 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: Internet Problem Solving Contest*/#include<cstdio>#define MAX 200000void readAndAdd( v   IQ[] , int const n , double & ave ){  static int  i;   static long long total;  for ( total = 0 , i = 0; i < n; i++ )    {      scanf( "%d" , &IQ[ i ] );      total += IQ[ i ] ;    }  ave = static_cast< double >( total ) / static_cast< double >( n );}int main(){  double aveCs , aveEE;  int  i , t  , nOfS , j  , nCs, nEE;  long long csIQ[ MAX ] , EEIQ[ MAX ];  scanf( "%d" , &t );  for ( i = 0; i < t; i++ )    {      scanf( "%d%d" , &nCs , &nEE );      readAndAdd( csIQ , nCs , aveCs );      readAndAdd( EEIQ , nEE , aveEE );      for ( nOfS = 0 , j = 0; j < nCs; j++ )	{	  if ( csIQ[ j ] < aveCs && csIQ[ j ] > aveEE )	    nOfS++;	}      printf( "%d\n" , nOfS );    }  return 0;}          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -