PAT_A 1080 Graduate Admission

PAT_A 1080 Graduate Admission

分析

题目模拟一个志愿填报系统。按照总分数(入学考试分数G1与面试的分数G2)从高到低模拟填志愿。

  • 若两学生的总分(tot)、入学考试分数(G1)分别都相同,则认为排名相同。
  • 排名相同的学生填报同一所学校时可以超出学校计划配额(quota)。
  • 一位学生只能被一所学校录取。
  • 录取的表示这里采用了一个很大的bool数组,采用链表或其他结构或许可以提高性能?
  • 由于排序后原有序号会改变,每位学生需要记录排序前位置(id
  • 输出是按照学号(即输入的顺序id)的升序输出。

题目的描述

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:

  • 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 (≤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.

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

AC的代码

#include<bits/stdc++.h>

using namespace std;

class Student{
    public:
    int G1,G2,tot,id;
    array<int, 6> choice;
    Student(){
        choice.fill(false);
    };
};
class School{
    public:
    int quota,minstu,stulen;
    array<bool,40001> students;
    School(){
        stulen = 0;
        minstu = -1;
        students.fill(false);
    }
};
bool cmp(Student a,Student b){
    return a.tot == b.tot ?
        a.G1 > b.G1
        : a.tot>b.tot;
}
int main(){
    int N,M,K;
    array<School,101> sch;
    array<Student,40001> stu;
    scanf("%d%d%d",&N,&M,&K);
    for(int i=0;i<M;i++){
        scanf("%d",&sch[i].quota);
    }
    for(int i=0;i<N;i++){
        scanf("%d%d",&stu[i].G1,&stu[i].G2);
        stu[i].tot = stu[i].G1 + stu[i].G2;
        stu[i].id = i;
        for(int j=0;j<K;j++){
            scanf("%d",&stu[i].choice[j]);
        }
    }
    sort(stu.begin(),stu.begin()+N,cmp);
    for(int i=0;i<N;i++){
        for(int j=0;j<K;j++){
            if(sch[stu[i].choice[j]].quota>0
              || sch[stu[i].choice[j]].stulen>0 && stu[sch[stu[i].choice[j]].minstu].tot == stu[i].tot &&stu[sch[stu[i].choice[j]].minstu].G1 == stu[i].G1
              ){
                sch[stu[i].choice[j]].quota--;
                sch[stu[i].choice[j]].minstu = i;
                sch[stu[i].choice[j]].students[stu[i].id]=true;
                sch[stu[i].choice[j]].stulen++;
                break;
            }
        }
    }
    for(int i=0;i<M;i++){
        for(int j=0,c=0;j<sch[i].students.size()&&c<sch[i].stulen;j++){
            if(sch[i].students[j]&&c==0){
                printf("%d",j);
                c++;
            }
            else if(sch[i].students[j]){
                printf(" %d",j);
            }
        }
        printf("\n");
    }
    return 0;
}
posted @ 2022-01-26 18:25  ghosteq  阅读(19)  评论(0编辑  收藏  举报