PAT (Advanced Level) 1012 The Best Rank (25分)

本文详细解析了PAT(Advanced Level)1012题目《The Best Rank》的算法实现,介绍了如何处理学生在三门课程上的成绩,计算其在各科及平均成绩的最佳排名,并考虑了相同分数排名相同的情况,确保排名公正。文章提供了完整的C++代码示例,展示了如何使用结构体、排序和条件判断来解决复杂排名问题。

PAT (Advanced Level) 1012 The Best Rank (25分)

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C, M, E and A - Average of 4 students are given as the following:
StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input Specification:

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output Specification:

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output N/A.

Sample Input:

5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999

Sample Output:

1 C
1 M
1 E
1 A
3 A
N/A

这题有个2个坑
1.一个是平均分不要用double,直接转成整型,但是不能直接整除,要四舍五入
2.相同分数排名相同 即可能存在 1 1 3 4 5 6.这中排名,不然会掉2个点

#include <bits/stdc++.h>
using namespace std;

struct Score{
    int best, bestid, no;
    int v[4], rd[4];
};
int exist[1000005];
Score student[2005];
int n, m, id;
string p = "ACME";
bool cmp(Score a, Score b){return a.v[id] > b.v[id]; }
bool cmpid(Score a, Score b){return a.no < b.no; }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 0;i < n; i++){
        int s;
        cin >> s;
        exist[s] = i + 1;
        student[i].no = i;
        for (int j = 1; j <= 3; j++) cin >> student[i].v[j], student[i].v[0] += student[i].v[j];
        student[i].v[0] = (int)(1.0 * student[i].v[0] / 3);
    }
    for (id = 0; id <= 3; id++){
        sort(student, student + n, cmp);
        student[0].rd[id] = 1;
        for (int i = 1; i < n; i++){
            student[i].rd[id] = i + 1;
            if (student[i].v[id] == student[i - 1].v[id]) student[i].rd[id] = student[i - 1].rd[id];
        }
    }
    sort(student , student + n ,cmpid);
    for (int i = 0; i < n; i++){
        student[i].best = student[i].rd[0];
        student[i].bestid = 0;
        for (id = 1; id <= 3; id++){
            if (student[i].rd[id] < student[i].best){
                student[i].best = student[i].rd[id];
                student[i].bestid = id;
            }
        }
    }
    for (int i = 0; i < m; i++){
        int s;
        cin >> s;
        int _i = exist[s];
        if (_i == 0) cout << "N/A\n";
        else{
            cout << student[_i-1].best << " " << p[student[_i-1].bestid] << "\n";
        }
    }
    return 0;
}

内容概要:本文详细介绍了基于Matlab实现的“梯级水光互补系统最大化可消纳电量期望短期优化调度模型”,属于电力系统领域高水平科研成果的复现(EI级别)。该模型聚焦于梯级水电站与光伏发电系统的协同优化调度,通过构建短期优化调度框架,旨在提升可再生能源的电量消纳能力并最大化系统综合效益。研究采用先进的数学优化方法对水光资源进行联合调度,充考虑了光伏力的不确定性、水资源约束、系统运行边界条件及电力平衡要求,实现了在多重约束下的电量期望最大化目标。模型不仅具备严谨的理论基础,还具有良好的工程应用前景,适用于新能源高比例渗透背景下电力系统的优化调度研究与实践。; 适合人群:具备电力系统析、可再生能源利用或优化建模背景的研究生、科研人员及工程技术人员,特别适合致力于复现高水平学术论文(EI/顶刊)研究成果的学习者与开发者。; 使用场景及目标:① 学习并掌握梯级水电与光伏系统协同调度的建模思路与关键技术;② 熟悉基于Matlab的混合整数线性规划(MILP)或其他非线性优化方法在能源系统中的实际应用;③ 提升在新能源消纳、短期调度优化等方向的科研建模能力与代码实现水平,支持二次开发与创新研究。; 阅读建议:建议结合Matlab代码与优化理论同步研读,重点理解目标函数的设计逻辑、各类物理与运行约束的数学表达以及求解器的调用流程,推荐使用YALMIP等建模工具辅助实现,以提高模型构建效率与可读性,便于深入理解与后续拓展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值