1080 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 G​E​​, and the interview grade G​I​​. 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 G​E​​. 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 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.

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.

Sample Input:

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
 

Sample Output:

0 10
3
5 6 7
2 8

1 4

 

题意:

  模拟考试志愿填报和学校录取。

思路:

  首先按照成绩进行排序,成绩高的先选学校,按照所填报的志愿,依次选学校,当学校还有空余名额或该与学校最后录取的一个学生的排名相等,即被该学校录取。

  最后输出成绩的时候,要按照学生的id重新排序。

Code:

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 struct Student {
 6     int id;
 7     int Ge;
 8     int Gi;
 9     int fianl;
10     int rank;
11     vector<int> choices;
12 };
13 
14 bool cmp1(Student& a, Student& b) {
15     if (a.fianl == b.fianl)
16         return a.Ge > b.Ge;
17     else
18         return a.fianl > b.fianl;
19 }
20 
21 bool cmp2(Student& a, Student& b) { return a.id < b.id; }
22 
23 int main() {
24     int n, m, k;
25     cin >> n >> m >> k;
26     vector<Student> stu, sch[105];
27     vector<int> quota(m), count(m, 0);
28     for (int i = 0; i < m; ++i) cin >> quota[i];
29     for (int i = 0; i < n; ++i) {
30         int Ge, Gi;
31         cin >> Ge >> Gi;
32         vector<int> choices(k);
33         for (int j = 0; j < k; ++j) cin >> choices[j];
34         int final = Ge + Gi;
35         stu.push_back({i, Ge, Gi, final, 0, choices});
36     }
37     sort(stu.begin(), stu.end(), cmp1);
38     stu[0].rank = 1;
39     for (int i = 1; i < n; ++i) {
40         if (stu[i].fianl == stu[i - 1].fianl && stu[i].Ge == stu[i - 1].Ge)
41             stu[i].rank = stu[i - 1].rank;
42         else {
43             stu[i].rank = stu[i - 1].rank + 1;
44         }
45     }
46 
47     for (int i = 0; i < n; ++i) {
48         for (int j = 0; j < k; ++j) {
49             int schid = stu[i].choices[j];
50             int lastid = count[schid] - 1;
51             if (quota[schid] > count[schid] ||
52                 sch[schid][lastid].rank == stu[i].rank) {
53                 sch[schid].push_back(stu[i]);
54                 count[schid]++;
55                 break;
56             }
57         }
58     }
59 
60     for (int i = 0; i < m; ++i) {
61         sort(sch[i].begin(), sch[i].end(), cmp2);
62         for (int j = 0; j < sch[i].size(); ++j) {
63             if (j == 0)
64                 cout << sch[i][j].id;
65             else
66                 cout << " " << sch[i][j].id;
67         }
68         cout << endl;
69     }
70 
71     return 0;
72 }

本来以为是一道简单的题目,但是做的时候逻辑很混乱。刚开始想到两种录取方案,一种是按照学生的成绩,另一种是按照学校的报考志愿依次录取。但是第二种方法我越写越乱,后来也没有再想第一种方法应该怎么来写。

 

参考:https://www.liuchuo.net/archives/2453

 

posted @ 2020-04-29 21:17  Veritas_des_Liberty  阅读(156)  评论(0编辑  收藏  举报