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代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值