P5738 【深基7.例4】歌唱比赛 答案错误

P5738 【深基7.例4】歌唱比赛
各位,我在做洛谷题库的P5738 【深基7.例4】歌唱比赛,但不知道我为什么答案错误。
(QWQ)
题目如下:

img


以下是我编出来的代码:
代码一:

#include <bits/stdc++.h>
using namespace std;
const int mxn = 20;
priority_queue <double,vector<double>,less<double> >average_score;
double judge_max(double n)
{
    int maxnum = -0x7fffffff;
    if(maxnum < n)
    {
        maxnum = n;
    }
}
double judge_min(double n)
{
    int minnum = 0x7fffffff;
    if(minnum > n)
    {
        minnum = n;
    }
}
int main()
{
    double minimum_value[mxn], maximum_value[mxn], total_points, sum = 0;
    int n, m, score, maxnumber, minnumber;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        score = 0, maxnumber = 0, minnumber = 0, total_points = 0, sum = 0;
        for(int j = 0; j < m; j++)
        {
            cin >> score;
            sum += score;
            maxnumber = judge_max(score);
            minnumber = judge_min(score);
        }
        total_points = (sum - maxnumber - minnumber) / (m - 2);
        average_score.push(total_points);
    }
    printf("%.2lf", average_score.top());
    return 0;
}

代码二:

#include <bits/stdc++.h>
using namespace std;
priority_queue <double,vector<double>,greater<double> > score_min;
priority_queue <double,vector<double>,less<double> > score_max;
priority_queue <double,vector<double>,less<double> > total_score;
int main()
{
    double score[24], max_total_score, n, m, maximum, minimum, per_total_score = 0;
    for(int i = 0; i < n; i++)
    {
        memset(score, 0, sizeof(score));
        score_min.empty();
        score_max.empty();
        per_total_score = 0;
        for(int j = 0; j < m; j++)
        {
            cin >> score[j];
            score_min.push(score[j]);
            score_max.push(score[j]);
            per_total_score += score[j];
        }
        minimum = score_min.top();
        maximum = score_max.top();
        per_total_score = (per_total_score - (minimum + maximum)) / (m - 2);
        total_score.push(per_total_score);
    } 
    max_total_score = total_score.top();
    printf("%.2lf", max_total_score);
    return 0;
}

感谢各位朋友[doge]

代码一,判断最高分和最低分那里错了;

因为最高分和最低分需要与该组的其他数据来比较得出,所以使用自定义函数是无法得出最高分和最低分,可以使用if条件来判断得出最高分和最低分。

修改如下:


#include <bits/stdc++.h>
using namespace std;
const int mxn=20;
priority_queue <double,vector<double>,less<double> >average_score;

int main()
{
    double minimum_value[mxn], maximum_value[mxn], total_points, sum = 0;

    int n, m, score, maxnumber, minnumber;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        // 这里最低分默认设置为10,以便判断出该组的最低分
        score = 0, maxnumber = 0, minnumber = 10, total_points = 0, sum = 0;
        for(int j = 0; j < m; j++)
        {
            cin >> score;
            sum += score;
            
            // 将 最高分变量maxnumber逐个与读取的分数比较,并将较大的值赋值给maxnumber
            // 计算完成后,即可得出每组的最高分 
            if(maxnumber<score){
                maxnumber=score;
            } 
            
             // 同上,将 最低分变量minnumber逐个与读取的分数比较,并将较大的值赋值给minnumber
            // 计算完成后,即可得出每组的最低分 
            if(minnumber>score){
                minnumber=score;
            }
        }
        total_points = (sum - maxnumber - minnumber) / (m - 2);
        //printf("\ni=%d , maxnumber=%d, minnumber=%d, total_points=%.2f\n",i,maxnumber,minnumber,total_points);
       average_score.push(total_points);
      
    }

    
    printf("%.2f", average_score.top());

    return 0;
}

img