题目1005:Graduate Admission

题目描述:

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 (GE + GI) / 2. 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.

输入:

Each input file may contain more thanone test case. Each case starts with a line containing three positive integers: N (≤40,000), the total number of applicants; M (≤100), the total number of graduate schools; and K (≤5), 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+K 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 M-1, and the applicants are numbered from 0 to N-1.

输出:

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.

样例输入:11 6 32 1 2 2 2 3100 100 0 1 260 60 2 3 5100 90 0 3 490 100 1 2 090 90 5 1 380 90 1 0 280 80 0 1 280 80 0 1 280 70 1 3 270 80 1 2 3100 100 0 2 4样例输出:0 1035 6 72 81 4

#include <iostream>#include <stdio.h>#include <algorithm>using namespace std;class Applicant{public :int id; //用于排序输出int GE;int GI;int choise[5];};class School{public :int quota;Applicant app[100];int front,rear; //相当于链表的头尾指针};bool cmp(Applicant app1, Applicant app2){if(app1.GE + app1.GI != app2.GE + app2.GI)return app1.GE + app1.GI > app2.GE + app2.GI;elsereturn app1.GE > app2.GE;}bool cmpid(Applicant app1, Applicant app2){return app1.id < app2.id;}int main(){int N;//applicantint M;//schoolint K;//choiceApplicant applicants[40000];School school[100];while(scanf("%d %d %d",&N,&M,&K)!=EOF){/*初始化school数据*/for(int i = 0; i < M; i++){cin >> school[i].quota ;school[i].rear = 0;school[i].front = 0;}/*初始化applicants数据*/for(int i = 0; i < N; i++){//Applicant applicant = applicants[i];int GE, GI;cin >> GE;cin >> GI;applicants[i].GE = GE;applicants[i].GI = GI;applicants[i].id = i;for(int j = 0; j < K; j++){cin >> applicants[i].choise[j];}}/*将学生按成绩排序*/sort(applicants,applicants+N,cmp);/*遍历每一个学生 */for(int i = 0; i < N; i++){/*遍历学生的志愿*/for(int j = 0; j < K;j++){/*如果学校有名额,直接录取*/if(school[applicants[i].choise[j]].quota >0){school[applicants[i].choise[j]].app[school[applicants[i].choise[j]].rear++] = applicants[i];school[applicants[i].choise[j]].quota–;break;}/*如果没有名额 将该学生与该学校最后一名学生比较*/else if(applicants[i].GE == school[applicants[i].choise[j]].app[school[applicants[i].choise[j]].rear-1].GE&&applicants[i].GI == school[applicants[i].choise[j]].app[school[applicants[i].choise[j]].rear-1].GI){school[applicants[i].choise[j]].app[school[applicants[i].choise[j]].rear++] = applicants[i];school[applicants[i].choise[j]].quota–;break;}}}/*输出每个学校录取者的id*/for(int i = 0; i < M; i++){//front == rear 表示没有学生录入if(school[i].rear == school[i].front){cout << endl;} else{//按学生id排序sort(school[i].app, school[i].app+school[i].rear,cmpid);cout << school[i].app[school[i].front++].id;while(school[i].front != school[i].rear){cout << ' '<<school[i].app[school[i].front++].id;}cout << endl;}}}}

,生活若剥去了理想梦想幻想,那生命便只是一堆空架子

题目1005:Graduate Admission

相关文章:

你感兴趣的文章:

标签云: