08: white blood cell count

Total time limit: 1000ms Memory Limit: 65536kB
describe
hospital leukocyte sampling number of samples during the treatment of a clinical case n shares for analyzing the effect of antibiotic treatment for some new cases. In order to reduce the analytical error, first parts of n samples removed from a maximum value sample and a minimum value of the sample, then the average of the remaining n-2 as an effective sample analysis indicators. Meanwhile, in order to observe the effect of the antibiotic is stable, but also gives the average value of the error, i.e. the difference between the maximum value and the absolute value of the average value of all valid samples (i.e., not including the two samples have been deducted).

Now you write programs, according to the n sample values ​​provided, the number of white blood cells and calculates the average error of the corresponding cases.

Input
of the first input line is a positive integer n (2 <n <= 300 ), showed a total of n samples.
The following there are n rows, each acts a float, corresponding to the number of leukocytes, in units of 10 ^ 9 / L. Between Number and separated by a space.
Output
output two floating point numbers, separated by a space in the middle. Respectively, the average number of leukocytes and the corresponding error, the unit is 10 ^ 9 / L. 2 results to be retained after the decimal.
Input Sample
5
12.0
13.0
11.0
9.0
10.0
Sample Output
11.00 1.00
tips
to avoid floating-point precision error is too large, use double.

#include<iostream>
#include<cstring>
#include<string>
#include<math.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	//放入输入的数值,放入计算后的平均值 
	double whiteCell[n+5];
	double averageMargin[n+5];
	memset(averageMargin,0,sizeof(averageMargin));
	//求和来计算平均值 
	double average;
	double sum=0;
	//计算平均值时去掉最小最大值 
	double min=100000.0;
	double max=-1.0;
	int minIndex,maxIndex;
	
	for(int i=1;i<=n;i++){
		scanf("%lf",&whiteCell[i]);
		sum+=whiteCell[i];
		if(whiteCell[i]<min){
			min=whiteCell[i];
			minIndex=i;
		}
		if(whiteCell[i]>max){
			max=whiteCell[i];
			maxIndex=i;
		}
	}
	
	sum-=min;
	sum-=max;
	average=sum/(n-2);
	
	//用变量记录与平均值最大的差量 
	double maxAverageMargin=0;
	for(int i=1;i<=n;i++){
	//计算与平均值的绝对值时不包括最小最大值时的情况 
		if(i!=minIndex&&i!=maxIndex){
			averageMargin[i]=fabs(whiteCell[i]-average);
			if(maxAverageMargin<averageMargin[i])
			maxAverageMargin=averageMargin[i];
		}
	}
	
	printf("%.2lf %.2lf",average,maxAverageMargin);
	
	
	return 0;
} 
Published 36 original articles · won praise 0 · Views 342

Guess you like

Origin blog.csdn.net/weixin_44437496/article/details/104043755