30分求助

B2095 白细胞计数

LIUYIFAN5 @ 2023-08-31 10:47:54

#include<bits/stdc++.h>
double a[305],zd=-1,zx=999999,z=0,pingjunshu;
int n,max1,min1,x,y;
using namespace std;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>zd){
            zd=a[i];
            max1=i;
        }
        if(a[i]<zx){
            zx=a[i];
            min1=i;
        }
        z+=a[i]-zd-zx;
    }
    pingjunshu=z/(n-2);
    zd=0;
    for(int i=1;i<=n;i++){
        if(i!=x&&i!=y){
            if(fabs(a[i]-pingjunshu)>zd){
                zd=fabs(a[i]-pingjunshu);
            }
        }
    }
    cout<<fixed<<setprecision(2)<<pingjunshu<<" "<<zd;
    return 0;
}
#include<bits/stdc++.h>
double a[305],zd=-1,zx=999999,z=0,pingjunshu;
int n,max1,min1,x,y;
using namespace std;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>zd){
            zd=a[i];
            max1=i;
        }
        if(a[i]<zx){
            zx=a[i];
            min1=i;
        }
        z+=a[i]-zd-zx;
    }
    pingjunshu=z/(n-2);
    zd=0;
    for(int i=1;i<=n;i++){
        if(i!=x&&i!=y){
            if(fabs(a[i]-pingjunshu)>zd){
                zd=fabs(a[i]-pingjunshu);
            }
        }
    }
    cout<<fixed<<setprecision(2)<<pingjunshu<<" "<<zd;
    return 0;
}

by LIUYIFAN5 @ 2023-08-31 10:48:20

6,复制了两遍


by LIUYIFAN5 @ 2023-08-31 10:50:24

#include<bits/stdc++.h>
double a[305],zd=-1,zx=999999,z=0,pingjunshu;
int n,max1,min1,x,y;
using namespace std;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]>zd){
            zd=a[i];
            max1=i;
        }
        if(a[i]<zx){
            zx=a[i];
            min1=i;
        }
        z+=a[i]-zd-zx;
    }
    pingjunshu=z/(n-2);
    zd=0;
    for(int i=1;i<=n;i++){
        if(i!=x&&i!=y){
            if(fabs(a[i]-pingjunshu)>zd){
                zd=fabs(a[i]-pingjunshu);
            }
        }
    }
    cout<<fixed<<setprecision(2)<<pingjunshu<<" "<<zd;
    return 0;
}

by Hagasei @ 2023-08-31 11:18:17

@LIUYIFAN5 总和减两个最值除以数量是平均数,不是每个数减两个最值的和


by nike1325 @ 2023-08-31 11:39:15


by nike1325 @ 2023-08-31 11:50:02

代码如下:

你代码我没看懂

#include<bits/stdc++.h>
using namespace std;
double a[1000],z=0,p,m=-10;
int n;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=2;i<n;i++) {
        z+=a[i];
    }
    p=z/(n-2.0);
    for(int i=2;i<n;i++)
        m=max(m,fabs(a[i]-p));
    printf("%.2lf %.2lf",p,m);
    return 0;
}

|