1012. The Best Rank (25)

本文介绍了一种用于解决PAT竞赛中学生排名问题的算法。该算法通过对学生在不同科目及平均成绩上的表现进行综合评估,确定每位学生的最优排名。文章详细展示了算法实现过程,包括如何处理重复排名情况,并提供了完整的C++代码示例。

1012. The Best Rank (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 Algebra), 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

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

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
主要思路:
1、使用map简历学生id与输入顺序号的联系
2、排名为实际排名,若有2个第一名,就没有第2名了
3、用一个二维数组存放每个学生的每科和平均成绩排名(不需要这样做,查哪个学生就去search这个学生的排名就好)
4、此代码通过PAT所有测试点,但是牛客网上一个测试点都通不过,why?
#include <iostream>
#include <string>
#include <map>

using namespace std;
#define Max_N 2001

void Rank_Per_Project(int* Array,int flag,int n,int (*Id)[6]) //将每一位学生某单个科目的排名存入Id二维数组的flag位
{
    int temp=0,count=1;
    for (int i=0; i<n; ++i)
    {
        temp=Array[i];
        count=1;
        for (int k=0; k<n; ++k)
        {
            if (Array[k]>temp)
            {
                count++;
            }
        }
        Id[i][flag]=count;
    }
}

void Rank(int *C,int *M,int* E,int*A,int (*Id)[6],int n,string str)
{
    Rank_Per_Project(C,1,n,Id); //处理每个学生C科目成绩的排名,并存入该学生Id数组
    Rank_Per_Project(M,2,n,Id);  //处理每个学生M科目成绩的排名,并存入该学生Id数组
    Rank_Per_Project(E,3,n,Id); //处理每个学生E科目成绩的排名,并存入该学生Id数组
    Rank_Per_Project(A,0,n,Id); //处理每个学生平均成绩的排名,并存入该学生Id数组
    
    int rank=n+1;
    int flag=-1;
    for (int i=0; i<n; ++i) //处理每一个学生的最佳排名,并存入Id[][4],Id[][5]放入标志,Id二维数组的每行按课程优先级放置,低优先级的科目必须排名更好,才能记录到该学生的最佳排名
    {
        rank=n+1;
        for (int k=0; k<4; ++k)
        {
            if (Id[i][k]<rank)
            {
                rank=Id[i][k];
                flag=k;
            }
        }
        Id[i][4]=rank;
        Id[i][5]=flag;
    }
}

int main(int argc, const char * argv[])
{
    
    int n,m;
    cin>>n>>m;
    
    int C[Max_N]={0};
    int M[Max_N]={0};
    int E[Max_N]={0};
    int A[Max_N]={0};
    int Id[Max_N][6]={0};
    
    map<string,int> relation;//创建每一个学生id与输入顺序号的关联,方便后续处理
    
    string id;
    for (int i=0; i<n; ++i)
    {
        cin>>id>>C[i]>>M[i]>>E[i];
        A[i]=C[i]+M[i]+E[i];
        relation[id]=i;
    }
    
    string str="ACME";
    Rank(C, M, E, A,Id,n,str);
    map<string,int>::iterator it;
    
    
    
    string search[Max_N];
    int sequence=0;
    for (int i=0; i<m; ++i)
    {
        cin>>search[i];
    }
    
    for (int i=0; i<m; ++i)
    {
        it=relation.find(search[i]);
        if (it!=relation.end())//成功找到该学生
        {
            sequence=it->second;
            cout<<Id[sequence][4]<<' '<<str[Id[sequence][5]]<<endl;;
        }else//未找到该学生信息
        {
            cout<<"N/A"<<endl;
        }
    }
   
    
    
    return 0;
}


【四轴飞行器】非线性三自由度四轴飞行器模拟器研究(Matlab代码实现)内容概要:本文围绕非线性三自由度四轴飞行器模拟器的研究展开,重点介绍了基于Matlab的建模与仿真方法。通过对四轴飞行器的动力学特性进行分析,构建了非线性状态空间模型,并实现了姿态与位置的动态模拟。研究涵盖了飞行器运动方程的建立、控制系统设计及数值仿真验证等环节,突出非线性系统的精确建模与仿真优势,有助于深入理解飞行器在复杂工况下的行为特征。此外,文中还提到了多种配套技术如PID控制、状态估计与路径规划等,展示了Matlab在航空航天仿真中的综合应用能力。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的高校学生、科研人员及从事无人机系统开发的工程技术人员,尤其适合研究生及以上层次的研究者。; 使用场景及目标:①用于四轴飞行器控制系统的设计与验证,支持算法快速原型开发;②作为教学工具帮助理解非线性动力学系统建模与仿真过程;③支撑科研项目中对飞行器姿态控制、轨迹跟踪等问题的深入研究; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注动力学建模与控制模块的实现细节,同时可延伸学习文档中提及的PID控制、状态估计等相关技术内容,以全面提升系统仿真与分析能力。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值