0分求助

B2095 白细胞计数

XXY2022 @ 2022-10-16 16:52:01

C++

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n[305];
    int a;
    cin >> a;
    for (int i = 0; i < a; i++)
    {
        cin >> n[i];
    }
    int max = n[0];
    int min = n[0];
    for (int i = 0; i < a; i++)
    {
        max = max < n[i] ? n[i] : max;
        min = min > n[i] ? n[i] : min;
    }
    int sum = 0;
    for (int i = 0; i < a; i++)
    {
        sum += n[i];
    }
    sum -= max;
    sum -= min;
    double s = sum * 1.0 / (a - 2);
    double imsub;
    imsub = (max - s) > (s - min) ? (max - s) : (s - min);
    printf("%.2d %.2d", s, imsub);
    return 0;
}

by randnameaaa @ 2022-10-16 16:58:24

读读题吧


by XXY2022 @ 2022-10-16 17:04:07

@randnameaaa
?


by randnameaaa @ 2022-10-16 17:07:52

求的是对剩余有效样本的最小绝对值,而不是与除去的那两个


by randnameaaa @ 2022-10-16 17:09:55

还有输出用%.2lf而不是%.2d


by XXY2022 @ 2022-10-16 17:16:57

@randnameaaa
求的是对剩余有效样本的最小绝对值,而不是与除去的那两个
所以怎么做?


by randnameaaa @ 2022-10-16 17:19:42

排序,然后对中间 2N-1 个数取平均,计算最小绝对值

应该自己多思考,提高代码能力


by LSC_IS_SB @ 2023-06-18 08:25:00

include<bits/stdc++.h>

using namespace std;

int n;

double a[10000],e,x;

int main() {

scanf("%d",&n);
for(int i=1;i<=n;i++){
    cin>>a[i];
    e+=a[i];
}

sort(a+1,a+n+1); //快排

e=e-a[1]-a[n];//减去最小最大值
e/=(n-2);

if(e-a[2]<=a[n-1]-e)x=a[n-1]-e;
else x=e-a[2];//求最大误差

printf("%.2f %.2f",e,x);

} ```cpp


|