啊啊啊,为啥测试样例第二个是0.00啊

B2095 白细胞计数

maodan11hao @ 2024-07-27 19:17:31

#include<bits/stdc++.h>
using namespace std;
double maxx=0,minn=2000000000;
int n; 
double t[309],cnt=0;
double a=0;
bool q=true,w=true;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t[i];
        if(t[i]>maxx)maxx=t[i];
        if(t[i]<minn)minn=t[i];
        cnt+=t[i];
    }
    double ans=cnt/n;
    cout<<fixed<<setprecision(2)<<ans<<" ";
    for(int i=0;i<n;i++){
        if(q){
            if(t[i]==maxx){
                q=false;
                continue;
            }
        }
        if(w){
            if(t[i]==minn){
                w=false;
                continue;
            }
        }
        a+=t[i];
    }
    a/=(n-2);
    a-=ans;
    a=abs(a);
    cout<<fixed<<setprecision(2)<<a;
    return 0;
}

by pff20121005 @ 2024-11-23 15:18:27

#include<iostream>
#include<cmath>
using namespace std;
double a[100000];
int main(){
    int n,maxi = 1,mini = 1;
    double y = 0,maxn = -1,sum = 0;
    cin>>n;
    for(int i = 1;i <= n;i++){
        cin>>a[i];
        sum += a[i];
        if(a[i] > a[maxi])maxi = i;
        if(a[i] < a[mini])mini = i; 
    }
    y = (sum - a[maxi] - a[mini]) / (n - 2.0);
    for(int i = 1;i <= n;i++){
        if(i != maxi && i != mini){
            if(fabs(a[i] - y) > maxn)maxn = fabs(a[i] - y);
        }
    }
    printf("%.2lf %.2lf",y,maxn);
    return 0;
}

|