PAT_A1080#Graduate Admission

Source:

PAT A1080 Graduate Admission (30 分)

Description:

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.

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

Keys:

  • 模拟题

Code:

 1 /*
 2 Data: 2019-07-14 18:26:36
 3 Problem: PAT_A1080#Graduate Admission
 4 AC: 39:42
 5 
 6 题目大意:
 7 初试Ge,复试Gi,总分(Ge+Gi)/2
 8 按照总分,初试,依次排名;
 9 K个志愿,按照学校招生名额依次录取
10 相同排名且相同志愿的考生,无论招生名额是否已满,都要录取
11 输入:
12 第一行给出,考生数N<=4e4,学校数M<=1e2,志愿数K<=5
13 接下来一行,各学校的招生名额(0~m-1)
14 接下来N行,Ge,Gi,K个志愿
15 输出:
16 各学校的录取结果,考生号递增(0~n-1)
17 未招生则打印空行
18 
19 基本思路:
20 静态存储考生信息,用考生编号替代数据项排名
21 创建学校录取信息的列表,按照排名依次录取
22 */
23 
24 #include<cstdio>
25 #include<vector>
26 #include<algorithm>
27 using namespace std;
28 const int N=1e5,M=110,K=10;
29 struct node
30 {
31     int ge,gi,g;
32     int se[K];
33 }info[N];
34 int quota[M],link[N];
35 vector<int> sch[M];
36 
37 bool cmp(const int &a, const int &b)
38 {
39     if(info[a].g != info[b].g)
40         return info[a].g > info[b].g;
41     else
42         return info[a].ge > info[b].ge;
43 }
44 
45 int main()
46 {
47 #ifdef    ONLINE_JUDGE
48 #else
49     freopen("Test.txt", "r", stdin);
50 #endif
51 
52     int n,m,k;
53     scanf("%d%d%d", &n,&m,&k);
54     for(int i=0; i<m; i++)
55         scanf("%d", &quota[i]);
56     for(int i=0; i<n; i++)
57     {
58         link[i]=i;
59         scanf("%d%d", &info[i].ge,&info[i].gi);
60         for(int j=0; j<k; j++)
61             scanf("%d", &info[i].se[j]);
62         info[i].g = info[i].ge + info[i].gi;
63     }
64     sort(link,link+n,cmp);
65     for(int i=0; i<n; i++)
66     {
67         int id = link[i];
68         for(int j=0; j<k; j++)
69         {
70             int cho = info[id].se[j];
71             int len = sch[cho].size();
72             if(len < quota[cho]){
73                 sch[cho].push_back(id);
74                 break;
75             }
76             else{
77                 int stu = sch[cho][len-1];
78                 if(info[stu].g==info[id].g && info[stu].ge==info[id].ge){
79                     sch[cho].push_back(id);
80                     break;
81                 }
82             }
83         }
84     }
85     for(int i=0; i<m; i++)
86     {
87         sort(sch[i].begin(),sch[i].end());
88         for(int j=0; j<sch[i].size(); j++)
89             printf("%d%c", sch[i][j],j==sch[i].size()-1?'\n':' ');
90         if(sch[i].size() == 0)
91             printf("\n");
92     }
93 
94     return 0;
95 }

猜你喜欢

转载自www.cnblogs.com/blue-lin/p/11185289.html