PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

1080 Graduate Admission (30 分)
 

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

 

题意:

有n个学生,m个学校,每个人可以填报的志愿为k个,每个人有两个成绩,笔试成绩GE,口试成绩GI,排名按照GE和GI的平均值计算,如果平均值相同,则按照GE排序,如果GE相同,则两学生排名相同

学校的录取规则为:按照成绩排序,再按照每一个 学生填报志愿的顺序,一次向下进行学校判断,如果学校没有收满学生,则录取,如果已经收满学生,但是最后一名收的学生和当前学生排名相同,即使名额超限,也会录取该学生
————————————————
版权声明:本文为CSDN博主「阿_波_」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/li1615882553/article/details/86380237

题解:

结构体排序,模拟即可

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n,m,k;
struct node{
    int id;
    int rank;
    int ge,gi;
    vector<int>cho;
}a[40005];
int num[205];
int ran[205];
vector<int>sch[205];
bool cmp(node x,node y){
    if((x.ge+x.gi)==(y.ge+y.gi)){
        return x.ge>y.ge;
    }else{
        return (x.ge+x.gi)>(y.ge+y.gi);
    }
}
bool cmp2(int x,int y){
    return x<y;
}
int main(){
    cin>>n>>m>>k;
    memset(ran,0,sizeof(ran));
    for(int i=0;i<m;i++) cin>>num[i];
    for(int i=0;i<n;i++){
        cin>>a[i].ge>>a[i].gi;
        a[i].id=i;
        for(int j=1;j<=k;j++){
            int x;
            cin>>x;
            a[i].cho.push_back(x);
        }
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++){
        if(i==0) a[i].rank=1;//计算排名 
        else{
            if(a[i].ge==a[i-1].ge && a[i].gi==a[i-1].gi){
                a[i].rank=a[i-1].rank;
            }else{
                a[i].rank=a[i-1].rank+1;
            }
        }
        for(int j=0;j<k;j++){//开始分流志愿 
            int x=a[i].cho.at(j);
            if(num[x]>0||ran[x]==a[i].rank){//排名相同也可 
                sch[x].push_back(a[i].id);
                num[x]--;
                if(num[x]==0) ran[x]=a[i].rank;
                break;
            }
        }
    }    
    for(int i=0;i<m;i++){
        sort(sch[i].begin(),sch[i].end(),cmp2);//学校内部排序 
        if(sch[i].size()!=0){    
            for(int j=0;j<sch[i].size();j++){
                cout<<sch[i].at(j);
                if(j!=sch[i].size()-1) cout<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}

 

发布了756 篇原创文章 · 获赞 66 · 访问量 11万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 像素格子 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览