题目1005:Graduate Admission

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:2534

解决:704

题目描述:

    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 than 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 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 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
来源:
2011年浙江大学计算机及软件工程研究生机试真题
 1 #include <iostream>
 2 #include <vector>
 3 #include <algorithm>
 4 using namespace std;
 5 struct student{
 6     int stu_num;
 7     int GE;
 8     int GI;
 9     int FG;
10     vector<int> schs_app;
11 };
12 struct school{
13     int quota;
14     vector<int> stus_admt;
15     student last_admt;
16 };
17 bool rank_equal(student s1,student s2){
18     return (s1.GE == s2.GE && s1.FG == s2.FG);
19 }
20 bool admit(school sh){
21     return (sh.stus_admt.size() < sh.quota);
22 }
23 bool cmp(const student &s1,const student &s2){
24     if(s1.FG == s2.FG){
25         if(s1.GE == s2.GE) return s1.stu_num < s2.stu_num;
26         else return s1.GE > s2.GE;
27     }
28     return s1.FG > s2.FG;
29 }
30 bool result_cmp(const int &s1,const int &s2){
31     return s1<s2;
32 }
33 int main(){
34     int sch_num,stu_num,appNum_allw;
35     while(cin>>stu_num>>sch_num>>appNum_allw){
36         vector<school *> sch_list;
37         while(sch_num-- > 0){
38             school *p_sch = new school;
39             cin>>p_sch->quota;
40             sch_list.push_back(p_sch);
41         }
42         vector<student > stu_list;
43         for(int i = 0; i < stu_num; i++){
44             student stu;
45             cin>>stu.GE>>stu.GI;
46             stu.stu_num = i;
47             stu.FG = (stu.GE + stu.GI)/2;
48             int num_schs_applctd = appNum_allw;
49             while(num_schs_applctd-- > 0){
50                 int sch_num;
51                 cin>>sch_num;
52                 stu.schs_app.push_back(sch_num);
53             }
54             stu_list.push_back(stu);
55         }
56         sort(stu_list.begin(),stu_list.end(),cmp);
57         for(int i = 0; i < stu_list.size(); i++){
58             for(int j = 0; j < stu_list[i].schs_app.size(); j++){
59                 int sch_num = (stu_list[i].schs_app)[j];
60                 if(admit(*(sch_list[sch_num]))){
61                     ((sch_list[sch_num])->stus_admt).push_back(stu_list[i].stu_num);
62                     (sch_list[sch_num])->last_admt = stu_list[i];
63                     break;
64                 }
65                 else if(i > 0) if(rank_equal(stu_list[i],(sch_list[sch_num])->last_admt)){
66                     ((sch_list[sch_num])->stus_admt).push_back(stu_list[i].stu_num);
67                     (sch_list[sch_num])->last_admt = stu_list[i];
68                     break;
69                 }
70             }
71         }
72         for(int i = 0; i < sch_list.size(); i++){
73             sort(sch_list[i]->stus_admt.begin(),sch_list[i]->stus_admt.end(),result_cmp);
74             if(sch_list[i]->stus_admt.size() == 0) cout<<endl;
75             else{
76                 for(int j = 0; j < sch_list[i]->stus_admt.size(); j++){
77                     cout<<(sch_list[i]->stus_admt)[j];
78                     if(j != sch_list[i]->stus_admt.size() -1) cout<<" ";
79                     else cout<<endl;
80                 }
81             }
82         }
83         for(int i = 0; i < sch_list.size(); i++){
84             delete sch_list[i];
85         }
86     }
87     return 0;
88 }

 

posted on 2013-03-03 12:57  denallo  阅读(196)  评论(0编辑  收藏  举报

导航