求助

回复帖子

@NaCl__H2O 2020-09-06 16:03 回复
#include<bits/stdc++.h>
using namespace std;
int cj[1001][1001];
int n;
int m;
double maxx=0.0,minn=10000001.0;
double head[100001];
int sum=0;
int j;
double mxxx=0.0;

void hs(){
    for(int i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(cj[i][j]>maxx){
                maxx=cj[i][j];
            }
            if(cj[i][j]<minn){
                minn=cj[i][j];
            }
            sum+=cj[i][j];
        }
        sum=sum-minn-maxx;
        maxx=0;
        minn=0;
        head[i]=sum/(m-2);
        sum=0;
    }
    for(int i=1;i<n;i++){
        for(int k=i+1;k<=n;k++){
            if(head[i]<head[k]){
                float temp=head[i];
                head[i]=head[k];
                head[k]=temp;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(head[i]>mxxx)
        mxxx=head[i];
    } 
    printf("%.2lf",mxxx);

}

int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int k=1;k<=m;k++){
            cin>>cj[i][k];
        }
    }
    hs();
    return 0;
}

样例过了,但是wa三个点什么原因???

@zhzzhzzzz  2020-09-06 17:09 回复 举报

fixed: $sum$ 要用 $double$ QAQ

#include <bits/stdc++.h>
using namespace std;
int cj[1001][1001];
int n;
int m;
double maxx = 0.0, minn = 10000001.0;
double head;
double sum = 0;
int j;
double mxxx = 0.0;

void hs()
{
    for (int i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        {
            if (cj[i][j] > maxx)
            {
                maxx = cj[i][j];
            }
            if (cj[i][j] < minn)
            {
                minn = cj[i][j];
            }
            sum += cj[i][j];
        }
        sum = sum - minn - maxx;
        maxx = 0;
        minn = 0x3f3f3f3f;
        head = sum / (double)(m - 2);
        sum = 0;
        mxxx = max(mxxx, head);
    }
    printf("%.2lf", mxxx);
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int k = 1; k <= m; k++)
        {
            cin >> cj[i][k];
        }
    }
    hs();
    return 0;
}

码风就不改了 (

反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。