1 条题解

  • 3
    @ 2023-10-16 21:23:45

    如下

    #include<iostream>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    
    class student {
    public:
        int ids;
        double alls, ranks;
        student(int idr = 0, double avg = 0, double     rank = 0) {
        this->ids = idr;
        this->alls = avg;
        this->ranks = rank;
        }
    };
    
    bool compares(const student& x, const student& y) {
        if (x.ranks != y.ranks)return x.ranks > y.ranks;
        else if (x.ranks == y.ranks && x.alls != y.alls)return x.alls > y.alls;
        else if(x.alls == y.alls)return x.ids < y.ids;
    }
    
    const int maxn = 1005;
    double grade[maxn][8],stu[maxn],avg[8],ranksco[maxn][8],all[maxn];
    student st[maxn];
    
    int main() {
        int n = 0;
        cin >> n;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 8; j++) {
                cin >> grade[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            double ctr = 0;
            for (int j = 0; j < 8; j++) {
                ctr += grade[i][j];
            }
        stu[i] = ctr;
        }
    
        for (int j = 0; j < 8; j++) {
        double ctr = 0;
            for (int i = 0; i < n; i++) {
                ctr += grade[i][j];
            }
        avg[j] = ctr / n;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 8; j++) {
                double ctr = 0;
                for (int i = 0; i < n; i++) {
                    ctr += abs(grade[i][j] - avg[j]);
                }
                if (ctr == 0)ranksco[i][j] = 0;
                else if (ctr)ranksco[i][j] = n * (grade[i][j] - avg[j]) / ctr;
            }
        }
        for (int i = 0; i < n; i++) {
            all[i] = ranksco[i][0] + ranksco[i][1] + ranksco[i][2] + 0.8 * (ranksco[i][3] + ranksco[i][4] + ranksco[i][5] + ranksco[i][6] + ranksco[i][7]);
        }
        for (int i = 0; i < n; i++) {
            st[i].ids = i + 1;
            st[i].alls = stu[i];
            st[i].ranks = all[i];
        }
        sort(st, st + n, compares);
        for (int i = 0; i < n; i++) {
            cout << st[i].ids <<  endl;
        }
        return 0;
    }
    
    • 1

    信息

    ID
    1807
    时间
    1000ms
    内存
    256MiB
    难度
    9
    标签
    递交数
    10
    已通过
    6
    上传者