求助,只绿了两个

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

@[wsllk22](/user/1320251) 为啥要排序啊,直接一边输入一边找最大最小值就好了呀
by 11514zbs @ 2024-07-13 12:42:46


可以参考我的代码,虽然慢,~~但容易理解~~ ```cpp #include <bits/stdc++.h> using namespace std; int a[105][25], b[25]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; int ans = 0, maxx = -1; for (int i = 1; i <= n; i++) { b[25] = {0}; for (int j = 1; j <= m; j++) b[j] = a[i][j]; sort(b + 1, b + 1 + m); for (int j = 2; j <= m - 1; j++) ans += b[j]; if (ans > maxx) maxx = ans; ans = 0; } double p = (maxx * 1.0) / ((m - 2) * 1.0); printf("%.2lf", p); return 0; } ```
by TODAYS @ 2024-07-13 13:34:10


用 $sort$ 比较好做 下面贴我的一点小想法 ```cpp for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++) cin>>a[j]; sort(a+1,a+n+1); a[1]=0,a[n]=0; int tmp=0; for(int j=2;j<n;j++){ tmp+=a[j]; } mark[i]=tmp*1.0/(n-2); } sort(mark+1,mark+m+1); printf("%.2f",mark[m]); ``` 注意我的 $m$ 和 $n$ 与题干是相反的哟!
by FanZhiyu1 @ 2024-07-24 16:48:58


|