求助

B2095 白细胞计数

Irisss @ 2023-09-22 13:24:25

不知道是哪里的问题

#include<bits/stdc++.h>
using namespace std;

float point[1000];

int main(){
    int n;
    cin>>n;

    float max=-10000;
    float min=100000000;
    float sum=0;

    for(int i=1;i<=n;i++){
        cin>>point[i];
        if(point[i]<min){
            min=point[i];
        }
        if(point[i]>max){
            max=point[i];
        }
        sum+=point[i];
    }

    float max1=-1000;
    float min1=100000000;
    for(int i=1;i<=n;i++){
        if(point[i]<max && point[i]>max1){
            max1=point[i];
        }
        if(point[i]>min && point[i]<min1){
            min1=point[i];
        }
    }

    sum-=max;
    sum-=min;

    printf("%.2f",sum/(n-2));
    cout<<" ";
//  sum=sum/(n-2);

//  max1=max1-sum;
//  min1=sum-min1;

//  cout<<max1<<min1;

    if(max1-sum/(n-2)>=sum/(n-2)-min1){
        printf("%.2f",max1-sum/(n-2));
    }

    if(max1-sum/(n-2)<sum/(n-2)-min1){
        printf("%.2f",sum/(n-2)-min1);
    }
    return 0;

}

by _cheems_ckr_ @ 2023-10-03 21:11:25

#include<bits/stdc++.h>
using namespace std;
int n;
double a[301],b,sum,maxn;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
        sum+=a[i];
    }
    sort(a+1,a+n+1);
    sum=sum-a[1]-a[n];
    b=1.00*sum/(n-2);
    printf("%.2f ",b);
    for(int i=2; i<=n-1; i++)
        if(fabs(b-a[i]) > maxn)
            maxn=fabs(b-a[i]);
    printf("%.2lf",maxn);
    return 0;
}

by _cheems_ckr_ @ 2023-10-03 21:12:52

你这好复杂啊 根本看不懂


by _cheems_ckr_ @ 2023-10-03 21:45:32

#include<bits/stdc++.h>
using namespace std;
double a[1001],b[1001];
int main(){
    int k,v;
    double w,maxn=-10000,minn=100001,s=0,n;
    //白细胞数量为实数
    scanf("%lf",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
    }
    for(int i=1;i<=n;i++){
        s+=a[i];
        if(a[i]>maxn){
            //求最大值
            maxn=a[i];
            k=i;
        }
        if(a[i]<minn){
            //求最小值
            minn=a[i];
            v=i;
        }
    }
    w=(s-a[v]-a[k])/(n-2.00);
    //求平均白细胞数量
    printf("%.2lf ",w);
    for(int i=1;i<=n;i++){
        if(i!=k&&i!=v){
            b[i]=abs(w-a[i]);
            //计算每个有效意样本与平均数的差值
        }else{
            b[i]=-10001;
            //否则赋值最小,不可能为最大值
        }
    }
    maxn=-10001;
    for(int i=1;i<=n;i++){
        if(b[i]>maxn){
            maxn=b[i];
            //找最大差值
        }
    }
    printf("%.2lf",maxn);
    return 0;
}

by _cheems_ckr_ @ 2023-10-03 21:47:07

这是信奥赛那本书上的


by AlisaSun @ 2023-10-06 21:40:29

把max和min换成maxn和minn试试?


|