PTA 甲级 1012 The Best Rank

我的思路是:结构体排序+二分查找

值得注意的是:1.名次的算法 如 99、 99 、98 对应的排名是1 、1、3; 2.选取的是个人的最佳排名;3.排序函数,参考别人的写法还可以这样写,减少代码量

struct Stu{
    int id;
    int score[4];//a,c,m,e
    int rk[4];
};
//全局变量pos,迭代pos控制对那门课进行排序
bool cmp1(Stu&a, Stu& b) {
    return a.score[pos] > b.score[pos];
}

#include
#include
#include
#include
#define MAXN 2010
using namespace std;

struct Stu{
    int id;
    int c,m,e,a;
    int c_rank,m_rank,e_rank,a_rank;
};
struct Stu stu[MAXN];
bool cmp(Stu&a,Stu&b){
    return a.idb.a;
}
bool cmp1(Stu&a,Stu&b){
    return a.c>b.c;
}
bool cmp2(Stu&a,Stu&b){
    return a.m>b.m;
}
bool cmp3(Stu&a,Stu&b){
    return a.e>b.e;
}

void work(Stu&s){
    string dis="ACME";
    int pos=0,rk=s.a_rank;
    if(s.c_rank>n>>m;
    for(int  i=0;i>stu[i].id>>stu[i].c>>stu[i].m>>stu[i].e;
        stu[i].a=round(1.0*(stu[i].c+stu[i].m+stu[i].e)/3);
    }
    //排序
    sort(stu,stu+n,cmp0);
    for(int i=0,rk=1;i>id;
        //二分查找
        int left=0,right=n-1;
        while(left

你可能感兴趣的:(PTA,算法,c++,数据结构)