1080 Graduate Admission (30分)

It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.

Each applicant will have to provide two grades: the national entrance exam grade GE​​, and the interview grade GI​​. The final grade of an applicant is (. The admission rules are:

  • The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.

  • If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE​​. If still tied, their ranks must be the same.

  • Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one's turn to be admitted; and if the quota of one's most preferred shcool is not exceeded, then one will be admitted to this school, or one's other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.

  • If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.

Input Specification:

Each input file contains one test case.

Each case starts with a line containing three positive integers: N (≤), the total number of applicants; M (≤), the total number of graduate schools; and K (≤), the number of choices an applicant may have.

In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.

Then N lines follow, each contains 2 integers separated by a space. The first 2 integers are the applicant's GE​​ and GI​​, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M1, and the applicants are numbered from 0 to N1.

Output Specification:

For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants' numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output an empty line correspondingly.

说人话就是高考录取,高考加上会考成绩总分决定排名,总分相同看高考成绩,都相同则排名相同。

很常规的面向对象题目,没有啥坑点。

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxsize=40002;
class Student{
    public:
    int id;
    int final_score;
    int enter_score;
    int inter_score;
    int rank;
    vector<int>want_to_go;
};
class School{
   public:
   int id;
   int size;
   int now_have;
   int last_rank=1;
   vector<int>students; 
};
Student students[maxsize];
School schools[maxsize];
bool cmp(Student a,Student b){
    if(a.final_score!=b.final_score){
        return a.final_score>b.final_score;
    }else if(a.enter_score!=b.enter_score){
        return a.enter_score>b.enter_score;
    }
}
void InitId(int n,int k){
    for(int i=0;i<n;i++){
        students[i].id=i;
    }
    for(int i=0;i<k;i++){
        schools[i].id=i;
    }
}
void InitRank(int num){//初始化排名
    students[0].rank=1;
    for(int i=1;i<num;i++){
        if(students[i].final_score==students[i-1].final_score&&students[i].enter_score==students[i-1].enter_score){
            students[i].rank=students[i-1].rank;
        }else{
            students[i].rank=i+1;
        }
    }
}
int main(){
    int student_num,school_num,choices;
    cin>>student_num>>school_num>>choices;
    InitId(student_num,school_num);//对id初始化,为了排序后保留id
    for(int i=0;i<school_num;i++){
        cin>>schools[i].size;
    }
    for(int i=0;i<student_num;i++){
        cin>>students[i].enter_score>>students[i].inter_score;
        students[i].final_score=students[i].enter_score+students[i].inter_score;//读入分数
        for(int j=0;j<choices;j++){
            int te;
            cin>>te;
            students[i].want_to_go.push_back(te);
        }
    }
    sort(students,students+student_num,cmp);
    InitRank(student_num);
    for(int i=0;i<student_num;i++){ 
        int rank=students[i].rank;
        for(int j=0;j<students[i].want_to_go.size();j++){//分别处理
            int sc=students[i].want_to_go[j];//想去的学校编号
            if(schools[sc].now_have<schools[sc].size){//该学校没有招满人
                schools[sc].now_have++;
                schools[sc].students.push_back(students[i].id);
                if(schools[sc].now_have==schools[sc].size)
                    schools[sc].last_rank=rank;
                break;
            }else if(rank<=schools[sc].last_rank){//虽然学校招满人了,但只要我不低于最低排名也可以进
                schools[sc].students.push_back(students[i].id);
                break;
            }
        }
    }
    for(int i=0;i<school_num;i++){
        if(schools[i].students.size()>0){
            sort(schools[i].students.begin(),schools[i].students.end());//保证学生编号从小到大
            for(int j=0;j<schools[i].students.size();j++){
                if(j!=0)cout<<" ";
                cout<<schools[i].students[j];
            }
        }
        cout<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/kalicener/p/13494586.html