20分求助!!!玄关

P5738 【深基7.例4】歌唱比赛

AC 求关 ```cpp #include<bits/stdc++.h> using namespace std; vector<vector<int>> scores; int n, m; int main() { scanf("%d%d", &n, &m); scores.resize(n); for (int i = 0; i < n; i++) { scores[i].resize(m); for (int j = 0; j < m; j++) { scanf("%d", &scores[i][j]); } sort(scores[i].begin(), scores[i].end()); } double maxAverage = 0; for (int i = 0; i < n; i++) { double sum = 0; for (int j = 1; j < m - 1; j++) { sum += scores[i][j]; } double average = sum / (m - 2); maxAverage = max(maxAverage, average); } printf("%.2lf\n", maxAverage); return 0; }
by HEROBRINEH @ 2024-04-09 17:51:09


```cpp #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<queue> #define ll long long using namespace std; int n,m,a[200][200]; double ans; int main() { cin >> n >> m; for(int i = 1; i <= n; i++) { int maxx = 0, minn = 11; //每次循环都要初始化maxx和minn double b = 0; //同上 for(int j = 1; j <= m; j++) { cin >> a[i][j]; b += a[i][j]; maxx = max(maxx, a[i][j]); minn = min(minn, a[i][j]); } b = (b - maxx - minn) / (m - 2); ans = max(ans, b); } printf("%.2f", ans); return 0; } ```
by W_Galaxy @ 2024-04-09 18:27:17


抱歉,minn变量应该初始化为**100**。~~手滑打错了~~
by W_Galaxy @ 2024-04-09 18:30:43


|