10分,求助,就例子对了

B2095 白细胞计数

haiweixin @ 2023-03-24 09:59:00

#include<stdio.h>
#include<cmath>
#pragma warning(disable:4996)

double a[330] = { 0 };

void paixu(double a[], int la, int ra)
{
    int l = la, r = ra;
    if (l >= r)
    {
        return;
    }
    double p = a[l];
    while (l < r)
    {
        while (l < r && a[r] >= p)
        {
            --r;
        }
        if (a[r] < p)
        {
            a[l] = a[r];
        }

        while (l < r && a[l] <= p)
        {
            ++l;
        }
        if (a[l] > p)
        {
            a[r] = a[l];
        }

        if (l >= r)
        {
            a[l] = p;
        }
    }
    paixu(a, la, l - 1);
    paixu(a, l + 1, ra);
}

int main(void)
{
    double z = 0, g = 0, t = 0, f = 0;
    int n;
    scanf("%d", &n);

    for (size_t i = 0; i < n; i++)
    {
        scanf("%lf", &a[i]);
        t += a[i];
    }

    paixu(a, 0, n - 1);

    t =t- (a[0] + a[n - 1]);
    t /= (double)(n - 2);

    g = g > abs(t - a[1]) ? g : abs(t - a[1]);
    g = g > abs(t - a[n-2]) ? g : abs(t - a[n-2]);

    printf("%.2lf %.2lf", t, g);

    return 0;
}

by sz_jinzikai @ 2023-06-08 18:32:24

@haiweixin 洛谷能用#pragma


by LSC_IS_SB @ 2023-06-18 08:18:35


#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);
}``` 

|