PAT甲级 1080 Graduate Admission (30分)

注意: 1. 当志愿学校满足招生人数并且与最后一名录取学生的排名相同即能破格录取

         2. 输出时注意 学校的录取学生学号需从小到大输出

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 using namespace std;
 6 const int maxn = 200005;
 7 typedef long long ll;
 8 struct st {
 9     int ge,gi,k[6],order,id;
10     double grade;
11 
12 }s[40005];
13 struct sc {
14     int s_num;//录取学生数量
15     int st_id[40005];//录取学生id
16     int st_order[40005];//录取学生排名
17     int max_num;//录取学生最大数
18 
19 }sc[105];
20 bool cmp(st p,st q) {
21     if(p.grade != q.grade) return p.grade > q.grade;
22     else return p.ge > q.ge;
23 }
24 int main() {
25     int n,m,k;
26     cin >> n >> m >> k;
27     for(int i = 0; i < m; i++) {
28         cin >> sc[i].max_num;
29         sc[i].s_num = 0;
30     }
31     for(int i = 0; i < n; i++) {
32         s[i].id = i;
33         cin >> s[i].ge >> s[i].gi;
34         s[i].grade = (s[i].ge + s[i].gi)*1.0/2.0;
35         for(int j = 0; j < k; j++) cin >> s[i].k[j];
36     }
37     sort(s,s+n,cmp);
38     s[0].order = 1;
39     for(int i = 1; i < n; i++) {//考生排名
40         if(s[i].grade == s[i-1].grade && s[i].ge == s[i-1].ge)
41             s[i].order = s[i-1].order;
42         else s[i].order = i+1;
43     }
44     for(int i = 0; i < n; i++) {
45         for(int j = 0; j < k; j++) {
46             int num = s[i].k[j];
47             int t = sc[num].s_num;
48             if(sc[num].s_num < sc[num].max_num) {//没有达到最大录取数
49                 sc[num].st_id[t] = s[i].id;
50                 sc[num].st_order[t] = s[i].order;
51                 sc[num].s_num++;
52                 break;
53             } else {
54                 if(s[i].order == sc[num].st_order[t-1]) {//到达了最大录取数 但是和该学校录取的最后一名学生排名相同 则 破格录取
55                     sc[num].st_id[t] = s[i].id;
56                     sc[num].st_order[t] = s[i].order;
57                     sc[num].s_num++;
58                     break;
59                 }
60             }
61         }
62     }
63 //    for(int i = 0; i < n; i++) {
64 //        cout << "id = " << s[i].id << " " << "order = " << s[i].order << " " << "grade = " << s[i].grade << " ge = " << s[i].ge << endl;
65 //    }
66 
67     for(int i = 0; i < m; i++) {
68         int t = sc[i].s_num;
69         sort(sc[i].st_id,sc[i].st_id+t);//对该学校录取的学生学号进行从小到大排序
70         if(sc[i].s_num > 0) {
71             for(int j = 0; j < t; j++) {
72                 cout << sc[i].st_id[j];
73                 if(j < t-1) cout << " ";
74             }
75         }
76         cout << endl;
77     }
78     return  0;
79 }

 

posted on 2020-02-05 13:28  一只小毛球  阅读(160)  评论(0编辑  收藏  举报

导航