样例对了还是只得了40;我的用sort比较简洁,大佬帮忙看一看,万分感谢

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

```cpp #include<bits/stdc++.h> using namespace std; int a[10001],n,m; double q,ans,x,minn=1e9,maxx; int main() { cin>>n>>m; for(int i=1; i<=n; ++i) { for(int j=1; j<=m; ++j) cin>>x,ans+=x,minn=min(x,minn),maxx=max(maxx,x); ans=ans-minn-maxx; ans=1.0*ans/(1.0*(m-2)); if(ans>q) q=ans; ans=0; minn=1e9; } printf("%0.2f\n",q); return 0; } ```
by ghx0052 @ 2023-06-20 11:18:30


@[guohaoxuan_](/user/748238) 就是你直接贴题解区代码吧
by Sqj147 @ 2023-07-01 09:29:03


@[qew12312](/user/916027) ```cpp #include <bits/stdc++.h> using namespace std; int main() { int m, n, i, y, sum, t; cin >> m >> n; int er[m][n]; double we[m] = {0}; for (i = 0; i < m; i++) { sum = 0; for (t = 0; t < n; t++) { cin >> er[i][t]; sum += er[i][t]; } sort(er[i], er[i] + n);// 排序排的是第 i 行数据 we[i] = (sum - er[i][0] - er[i][n - 1]) * 1.0 / (n - 2); } sort(we, we + m); cout << setiosflags(ios::fixed) << setprecision(2) << we[m - 1]; // system("pause"); return 0; } #include <bits/stdc++.h>// 关于数组存储的参考代码 using namespace std; typedef long long LL; const int maxn = 1e5 + 10; // 10 + 10 = 20 const double pi = 3.141593; // double p[maxn]; int p[25]; int main() { int n, m; cin >> n >> m; double res = 0; for (int i = 0; i < n; i ++) { int sum = 0; for (int j = 0; j < m; j ++) { cin >> p[j]; sum += p[j]; } sort(p, p + m); sum = (sum - p[0] - p[m - 1]); if (sum > res) res = sum; } printf("%.2f\n", res / (m - 2)); // system("pause"); return 0; } ```
by Sqj147 @ 2023-07-01 09:35:31


|