1080 Graduate Admission (30分)
Each applicant will have to provide two grades: the national entrance exam gradeGE, and the interview gradeGI. 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 gradeGE. If still tied, their ranks must be the same.
-
Each applicant may haveKchoices 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; andK(≤), the number of choices an applicant may have.
In the next line, separated by a space, there areMpositive integers. Thei-th integer is the quota of thei-th graduate school respectively.
ThenNlines follow, each contains2integers separated by a space. The first 2 integers are the applicant'sGEandGI, respectively. The nextKintegers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 toM−1, and the applicants are numbered from 0 toN−1.
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; }