P5738 【深基7.例4】歌唱比赛
各位,我在做洛谷题库的P5738 【深基7.例4】歌唱比赛,但不知道我为什么答案错误。
(QWQ)
题目如下:
以下是我编出来的代码:
代码一:
#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]