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 G**E, and the interview grade G**I. The final grade of an applicant is (G**E+G**I)/2. The admission rules are:
Each input file contains one 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 G**E and G**I, 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 3
2 1 2 2 2 3
100 100 0 1 2
60 60 2 3 5
100 90 0 3 4
90 100 1 2 0
90 90 5 1 3
80 90 1 0 2
80 80 0 1 2
80 80 0 1 2
80 70 1 3 2
70 80 1 2 3
100 100 0 2 4
0 10
3
5 6 7
2 8
1 4
据悉,2013年,浙江省约有100所研究生院准备处理超过40,000份申请。如果您可以编写一个程序来自动化录取程序,那将有很大帮助。
每位申请人必须提供两个等级:全国入学考试等级GE和面试等级GI。申请人的最终成绩是(GE + GI)/ 2。
录取规则是:
1.申请者根据他们的最终成绩进行排名,并将从排名列表的顶部逐一录取。
2.如果最终成绩相同,申请人将根据其国家入学考试成绩GE进行排名。如果仍然平局,他们的等级必须相同。
3.每个申请人可以有K个选择,录取将根据他/她的选择进行:如果按照排名表,轮到一个人被录取;如果没有超过自己最喜欢的学校的名额,那么一个人将被这所学校录取,或者一个人的其他选择将按顺序逐一考虑。如果一个人被所有首选学校拒绝,那么这个不幸的申请人将被拒绝。
如果排名平,并且相应的申请人申请同一所学校,那么该学校必须录取所有具有相同等级的申请人,即使其配额将被超过。
本题难度在于理解题意,即对学生结构体进行两次排序,第一次排序为实现学生间的成绩顺序排名,第二次排序为实现学校收学生的序号排序。而在处理同分,学校需收录额外学生的要求,仅需对排序后的学生群体进行依次判断是否录取的判断中加入对比学校已收录学生的最后一位即可,若同G和GE即可超额收录。
#include
#include
#include
using namespace std;
struct stu{
int GE, GI,G;
int no;
vector c;
};
bool cmp1(stu& a,stu& b){
if (a.G != b.G)
return a.G > b.G;
else
return a.GE > b.GE;
}
bool cmp2(stu& a, stu& b){
return a.no < b.no;
}
int main(){
int n, m, k;
int quota[110], cnt[110] = { 0 };
cin >> n >> m >> k;
for (int i = 0; i < m; i++)
cin >> quota[i];
vector student(n);
for (int i = 0; i < n; i++){
cin >> student[i].GE >> student[i].GI;
student[i].no = i;
student[i].G = student[i].GE + student[i].GI;
student[i].c.resize(k);
for (int j = 0; j < k; j++)
cin >> student[i].c[j];
}
vector sch[110];
sort(student.begin(),student.end(),cmp1);
for (int i = 0; i < n; i++)
for (int j = 0; j < k; j++){
int id = student[i].c[j];
int low = cnt[id] - 1;
if (cnt[id] < quota[id] || (student[i].G == sch[id][low].G) && student[i].GE == sch[id][low].GE){
sch[id].push_back(student[i]);
cnt[id]++;
break;
}
}
for (int i = 0; i < m; i++){
sort(sch[i].begin(), sch[i].end(), cmp2);
for (int j = 0; j < cnt[i]; j++){
if (j != 0)
cout << ' ';
cout << sch[i][j].no;
}
cout << endl;
}
return 0;
}
[[1]1080. Graduate Admission (30)-PAT甲级真题]((1条消息) 1080. Graduate Admission (30)-PAT甲级真题_it is said that in 2013, there were about 100 grad_柳婼的博客-CSDN博客)