//错误原因:没有正确判断误差,题意表达的是误差不包括最大值和最小值,但是如果样例里包含多个“最大值”“最小值”
//程序就会都排除掉,但是题意是让排除一个
//正解是记录最大值下标,和最小值下标,判断误差排除最大值最小值时直接判断下标即可;
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
double a[1000001];
int main(){
int n; cin >> n;
double maxn = -1e9,minn = 1e9,sum = 0,xb_maxn = 1,xb_minn = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
minn = min(minn,a[i]);
if(minn == a[i]) xb_minn = i;
maxn = max(maxn,a[i]);
if(maxn == a[i]) xb_maxn = i;
sum += a[i];
}
double e = (sum-minn-maxn)/(n-2); // 计算平均值
double maxx = 0;
for(int i = 1; i <= n; i++){
if(fabs(a[i]-e) > maxx && i != xb_maxn && i != xb_minn) maxx = fabs(a[i]-e); // 判断误差
}
printf("%.2lf %.2lf",e,maxx);
return 0;
}
YBT:1114:白细胞计数
最新推荐文章于 2024-07-16 15:14:23 发布